]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/thread/test.cpp
re-removing Makefile.in
[wxWidgets.git] / samples / thread / test.cpp
index 7d2c088b4f17f3875be3bccf1842538516cc269a..b350260d8efba3f56ef6a17803979e7840fbc991 100644 (file)
@@ -80,7 +80,7 @@ public:
 private:
     // helper function - creates a new thread (but doesn't run it)
     MyThread *CreateThread();
-    
+
     // crit section protects access to all of the arrays below
     wxCriticalSection m_critsect;
 
@@ -88,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;
 
@@ -142,10 +130,14 @@ void MyThread::WriteText(const wxString& text)
 
     // before doing any GUI calls we must ensure that this thread is the only
     // one doing it!
-    wxMutexGuiLocker guiLocker;
+
+    wxMutexGuiEnter();
+
     msg << wxTime().FormatTime() << ": " << text;
 
     m_frame->WriteText(msg);
+
+    wxMutexGuiLeave();
 }
 
 void MyThread::OnExit()
@@ -331,7 +323,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
@@ -381,7 +372,7 @@ void MyFrame::OnPauseThread(wxCommandEvent& WXUNUSED(event) )
     else
     {
         m_threads[n]->Pause();
-    
+
         SetStatusText("Thread paused.", 1);
     }
 }
@@ -389,24 +380,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++ )
@@ -457,5 +431,4 @@ void MyFrame::OnThreadExit(wxThread *thread)
     wxCriticalSectionLocker enter(m_critsect);
 
     m_threads.Remove(thread);
-    m_terminated.Add(thread);
 }