+// -----------------------------------------------------------------------------
+// pause/resume
+// -----------------------------------------------------------------------------
+
+wxThreadError wxThread::Pause()
+{
+ wxCriticalSectionLocker lock(m_critsect);
+
+ if ( p_internal->GetState() != STATE_RUNNING )
+ {
+ wxLogDebug("Can't pause thread which is not running.");
+
+ return wxTHREAD_NOT_RUNNING;
+ }
+
+ p_internal->SetState(STATE_PAUSED);
+
+ return wxTHREAD_NO_ERROR;
+}
+
+wxThreadError wxThread::Resume()
+{
+ wxCriticalSectionLocker lock(m_critsect);
+
+ if ( p_internal->GetState() == STATE_PAUSED )
+ {
+ p_internal->Resume();
+
+ return wxTHREAD_NO_ERROR;
+ }
+ else
+ {
+ wxLogDebug("Attempt to resume a thread which is not paused.");
+
+ return wxTHREAD_MISC_ERROR;
+ }
+}
+
+// -----------------------------------------------------------------------------
+// exiting thread
+// -----------------------------------------------------------------------------
+
+wxThread::ExitCode wxThread::Delete()
+{
+ m_critsect.Enter();
+ thread_state state = p_internal->GetState();
+ m_critsect.Leave();
+
+ switch ( state )
+ {
+ case STATE_NEW:
+ case STATE_EXITED:
+ // nothing to do
+ break;
+
+ case STATE_PAUSED:
+ // resume the thread first
+ Resume();
+
+ // fall through
+
+ default:
+ // set the flag telling to the thread to stop and wait
+ p_internal->Cancel();
+ }
+
+ return NULL;
+}
+
+wxThreadError wxThread::Kill()
+{
+ switch ( p_internal->GetState() )
+ {
+ case STATE_NEW:
+ case STATE_EXITED:
+ return wxTHREAD_NOT_RUNNING;
+
+ default:
+ if ( pthread_cancel(p_internal->GetId()) != 0 )
+ {
+ wxLogError(_("Failed to terminate a thread."));
+
+ return wxTHREAD_MISC_ERROR;
+ }
+
+ return wxTHREAD_NO_ERROR;
+ }
+}
+
+void wxThread::Exit(void *status)
+{
+ // first call user-level clean up code
+ OnExit();
+
+ // next wake up the threads waiting for us (OTOH, this function won't return
+ // until someone waited for us!)
+ p_internal->SignalExit();
+
+ p_internal->SetState(STATE_EXITED);
+
+ // delete both C++ thread object and terminate the OS thread object
+ delete this;
+ pthread_exit(status);
+}
+
+// also test whether we were paused
+bool wxThread::TestDestroy()