git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2473
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// state
// 2. The Delete() function blocks until the condition is signaled when the
// thread exits.
// state
// 2. The Delete() function blocks until the condition is signaled when the
// thread exits.
+ wxMutex m_mutex, m_end_mutex;
wxCondition m_cond;
// another (mutex, cond) pair for Pause()/Resume() usage
wxCondition m_cond;
// another (mutex, cond) pair for Pause()/Resume() usage
// this mutex is locked during almost all thread lifetime - it will only be
// unlocked in the very end
m_mutex.Lock();
// this mutex is locked during almost all thread lifetime - it will only be
// unlocked in the very end
m_mutex.Lock();
// this mutex is used in Pause()/Resume() and is also locked all the time
// unless the thread is paused
// this mutex is used in Pause()/Resume() and is also locked all the time
// unless the thread is paused
// note that m_mutex will be unlocked by the thread which waits for our
// termination
// note that m_mutex will be unlocked by the thread which waits for our
// termination
}
wxThreadError wxThreadInternal::Run()
}
wxThreadError wxThreadInternal::Run()
printf("Entering wait ...\n");
// entering Wait() releases the mutex thus allowing SignalExit() to acquire
// it and to signal us its termination
printf("Entering wait ...\n");
// entering Wait() releases the mutex thus allowing SignalExit() to acquire
// it and to signal us its termination
+ m_cond.Wait(m_end_mutex);
printf("Exiting wait ...\n");
// mutex is still in the locked state - relocked on exit from Wait(), so
// unlock it - we don't need it any more, the thread has already terminated
printf("Exiting wait ...\n");
// mutex is still in the locked state - relocked on exit from Wait(), so
// unlock it - we don't need it any more, the thread has already terminated
// reacquire GUI mutex
if ( wxThread::IsMain() )
// reacquire GUI mutex
if ( wxThread::IsMain() )
// as mutex is currently locked, this will block until some other thread
// (normally the same which created this one) unlocks it by entering Wait()
// as mutex is currently locked, this will block until some other thread
// (normally the same which created this one) unlocks it by entering Wait()
printf("Mutex acquired\n");
// wake up all the threads waiting for our termination
m_cond.Broadcast();
// after this call mutex will be finally unlocked
printf("Mutex acquired\n");
// wake up all the threads waiting for our termination
m_cond.Broadcast();
// after this call mutex will be finally unlocked
printf("Mutex unacquired\n");
}
printf("Mutex unacquired\n");
}