git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2091
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// removed from the array
wxArrayThread m_threads;
// 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;
// just some place to put our messages in
wxTextCtrl *m_txtctrl;
m_critsect.Enter();
wxThread *thread = m_threads.Last();
m_critsect.Enter();
wxThread *thread = m_threads.Last();
// it's important to leave critical section before calling Delete()
// because delete will (implicitly) call OnThreadExit() which also tries
// it's important to leave critical section before calling Delete()
// because delete will (implicitly) call OnThreadExit() which also tries
// set the frame title indicating the current number of threads
void MyFrame::OnIdle(wxIdleEvent &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++ )
size_t nRunning = 0,
nCount = m_threads.Count();
for ( size_t n = 0; n < nCount; n++ )
wxCriticalSectionLocker enter(m_critsect);
m_threads.Remove(thread);
wxCriticalSectionLocker enter(m_critsect);
m_threads.Remove(thread);
- m_terminated.Add(thread);