+ if ( !dontRunAtAll )
+ {
+ // call the main entry
+ wxLogTrace(TRACE_THREADS,
+ _T("Thread %ld about to enter its Entry()."),
+ THR_ID(pthread));
+
+ pthread->m_exitcode = thread->Entry();
+
+ wxLogTrace(TRACE_THREADS,
+ _T("Thread %ld Entry() returned %lu."),
+ THR_ID(pthread), wxPtrToUInt(pthread->m_exitcode));
+
+ {
+ wxCriticalSectionLocker lock(thread->m_critsect);
+
+ // change the state of the thread to "exited" so that
+ // wxPthreadCleanup handler won't do anything from now (if it's
+ // called before we do pthread_cleanup_pop below)
+ pthread->SetState(STATE_EXITED);
+ }
+ }
+
+ // NB: pthread_cleanup_push/pop() are macros and pop contains the matching
+ // '}' for the '{' in push, so they must be used in the same block!
+#ifdef wxHAVE_PTHREAD_CLEANUP
+ #ifdef __DECCXX
+ // under Tru64 we get a warning from macro expansion
+ #pragma message save
+ #pragma message disable(declbutnotref)
+ #endif
+
+ // remove the cleanup handler without executing it
+ pthread_cleanup_pop(FALSE);
+
+ #ifdef __DECCXX
+ #pragma message restore
+ #endif
+#endif // wxHAVE_PTHREAD_CLEANUP
+
+ if ( dontRunAtAll )
+ {
+ // FIXME: deleting a possibly joinable thread here???
+ delete thread;
+
+ return EXITCODE_CANCELLED;
+ }
+ else
+ {
+ // terminate the thread
+ thread->Exit(pthread->m_exitcode);
+
+ wxFAIL_MSG(wxT("wxThread::Exit() can't return."));
+
+ return NULL;
+ }
+}
+
+#ifdef wxHAVE_PTHREAD_CLEANUP
+
+// this handler is called when the thread is cancelled
+extern "C" void wxPthreadCleanup(void *ptr)
+{
+ wxThreadInternal::Cleanup((wxThread *)ptr);
+}
+
+void wxThreadInternal::Cleanup(wxThread *thread)
+{
+ if (pthread_getspecific(gs_keySelf) == 0) return;
+ {
+ wxCriticalSectionLocker lock(thread->m_critsect);
+ if ( thread->m_internal->GetState() == STATE_EXITED )
+ {
+ // thread is already considered as finished.
+ return;
+ }
+ }