X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c3d7e2d777b4c5892adadf3e658b8923645ae04..227e5e99cd140e628d431dc006d30447ed6ad81a:/samples/thread/test.cpp diff --git a/samples/thread/test.cpp b/samples/thread/test.cpp index dce914e8e6..c59942db53 100644 --- a/samples/thread/test.cpp +++ b/samples/thread/test.cpp @@ -73,7 +73,6 @@ public: void OnResumeThread(wxCommandEvent& event); void OnIdle(wxIdleEvent &event); - bool OnClose() { return TRUE; } // called by dying thread _in_that_thread_context_ void OnThreadExit(wxThread *thread); @@ -89,18 +88,6 @@ private: // removed from the array wxArrayThread m_threads; - // both of these arrays are only valid between 2 iterations of OnIdle(), - // they're cleared each time it is excuted. - - // the array of threads which finished (either because they did their work - // or because they were explicitly stopped) - wxArrayThread m_terminated; - - // the array of threads which were stopped by the user and not terminated - // by themselves - these threads shouldn't be Delete()d second time from - // OnIdle() - wxArrayThread m_stopped; - // just some place to put our messages in wxTextCtrl *m_txtctrl; @@ -140,11 +127,11 @@ MyThread::MyThread(MyFrame *frame) void MyThread::WriteText(const wxString& text) { wxString msg; - msg << wxTime().FormatTime() << ": " << text; // before doing any GUI calls we must ensure that this thread is the only // one doing it! wxMutexGuiLocker guiLocker; + msg << wxTime().FormatTime() << ": " << text; m_frame->WriteText(msg); } @@ -332,7 +319,6 @@ void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) ) m_critsect.Enter(); wxThread *thread = m_threads.Last(); - m_stopped.Add(thread); // it's important to leave critical section before calling Delete() // because delete will (implicitly) call OnThreadExit() which also tries @@ -390,24 +376,7 @@ void MyFrame::OnPauseThread(wxCommandEvent& WXUNUSED(event) ) // set the frame title indicating the current number of threads void MyFrame::OnIdle(wxIdleEvent &event) { - // first wait for all the threads which dies since the last call - { - wxCriticalSectionLocker enter(m_critsect); - - size_t nCount = m_terminated.GetCount(); - for ( size_t n = 0; n < nCount; n++ ) - { - // don't delete the threads which were stopped - they were already - // deleted in OnStopThread() - wxThread *thread = m_terminated[n]; - if ( m_stopped.Index(thread) == wxNOT_FOUND ) - thread->Delete(); - } - - m_stopped.Empty(); - m_terminated.Empty(); - } - + // update the counts of running/total threads size_t nRunning = 0, nCount = m_threads.Count(); for ( size_t n = 0; n < nCount; n++ ) @@ -458,5 +427,4 @@ void MyFrame::OnThreadExit(wxThread *thread) wxCriticalSectionLocker enter(m_critsect); m_threads.Remove(thread); - m_terminated.Add(thread); }