X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c1b293bb8df110ae772cd99fde09e5724730653a..f901941933f6bad712e855476b90c169315f9391:/samples/thread/thread.cpp diff --git a/samples/thread/thread.cpp b/samples/thread/thread.cpp index 6b0903cb82..7948c35a47 100644 --- a/samples/thread/thread.cpp +++ b/samples/thread/thread.cpp @@ -378,7 +378,7 @@ MyFrame::MyFrame(const wxString& title) wxMenu *menuHelp = new wxMenu; menuHelp->Append(THREAD_SHOWCPUS, wxT("&Show CPU count")); menuHelp->AppendSeparator(); - menuHelp->Append(THREAD_ABOUT, wxT("&About...")); + menuHelp->Append(THREAD_ABOUT, wxT("&About")); menuBar->Append(menuHelp, wxT("&Help")); SetMenuBar(menuBar); @@ -479,7 +479,7 @@ MyFrame::DoLogRecord(wxLogLevel level, wxDateTime(info.timestamp).FormatISOTime(), info.threadId == wxThread::GetMainId() ? wxString("main") - : wxString::Format("%x", info.threadId), + : wxString::Format("%lx", info.threadId), msg + "\n" ); } @@ -559,11 +559,11 @@ void MyFrame::OnStartThreads(wxCommandEvent& WXUNUSED(event) ) // have the lowest priority, the second - the highest, all the rest // the normal one if ( n == 0 ) - thr->SetPriority(WXTHREAD_MIN_PRIORITY); + thr->SetPriority(wxPRIORITY_MIN); else if ( n == 1 ) - thr->SetPriority(WXTHREAD_MAX_PRIORITY); + thr->SetPriority(wxPRIORITY_MAX); else - thr->SetPriority(WXTHREAD_DEFAULT_PRIORITY); + thr->SetPriority(wxPRIORITY_DEFAULT); threads.Add(thr); } @@ -597,6 +597,8 @@ void MyFrame::OnStartThread(wxCommandEvent& WXUNUSED(event) ) void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) ) { + wxThread* toDelete = NULL; + { wxCriticalSectionLocker enter(wxGetApp().m_critsect); // stop the last thread @@ -606,7 +608,15 @@ void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) ) } else { - wxGetApp().m_threads.Last()->Delete(); + toDelete = wxGetApp().m_threads.Last(); + } + } + + if ( toDelete ) + { + // This can still crash if the thread gets to delete itself + // in the mean time. + toDelete->Delete(); #if wxUSE_STATUSBAR SetStatusText(wxT("Last thread stopped."), 1);