+#if HAVE_THREAD_CLEANUP_FUNCTIONS
+// Only called when the thread is explicitely killed.
+
+void wxThreadInternal::PthreadCleanup(void *ptr)
+{
+ wxThread *thread = (wxThread *) ptr;
+
+ // The thread is already considered as finished.
+ if (thread->p_internal->GetState() == STATE_EXITED)
+ return;
+
+ // first call user-level clean up code
+ thread->OnExit();
+
+ // next wake up the threads waiting for us (OTOH, this function won't retur
+ // until someone waited for us!)
+ thread->p_internal->SetState(STATE_EXITED);
+
+ thread->p_internal->SignalExit();
+}
+#endif
+