]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/threadpsx.cpp
Regenerate wxstd.pot with the recently added translatable strings.
[wxWidgets.git] / src / unix / threadpsx.cpp
index 9c1afb98ded8810671038d18132362a69abd7138..95d8586f91379b1b1a00f6c98f90d5dae0d8ebeb 100644 (file)
@@ -45,6 +45,7 @@
 #include <pthread.h>
 #include <errno.h>
 #include <time.h>
+#include <sys/time.h>           // needed for at least __QNX__
 #ifdef HAVE_SCHED_H
     #include <sched.h>
 #endif
@@ -56,9 +57,7 @@
 // we use wxFFile under Linux in GetCPUCount()
 #ifdef __LINUX__
     #include "wx/ffile.h"
-    // For setpriority.
-    #include <sys/time.h>
-    #include <sys/resource.h>
+    #include <sys/resource.h>   // for setpriority()
 #endif
 
 #ifdef __VMS
@@ -725,7 +724,7 @@ public:
     void SetState(wxThreadState state)
     {
 #if wxUSE_LOG_TRACE
-        static const wxChar *stateNames[] =
+        static const wxChar *const stateNames[] =
         {
             wxT("NEW"),
             wxT("RUNNING"),
@@ -1477,6 +1476,11 @@ wxThreadError wxThread::Delete(ExitCode *rc)
             }
             //else: can't wait for detached threads
     }
+    
+    if (state == STATE_NEW)
+        return wxTHREAD_MISC_ERROR;
+            // for coherency with the MSW implementation, signal the user that 
+            // Delete() was called on a thread which didn't start to run yet.
 
     return wxTHREAD_NO_ERROR;
 }
@@ -1778,14 +1782,15 @@ static void ScheduleThreadForDeletion()
 
 static void DeleteThread(wxThread *This)
 {
-    // gs_mutexDeleteThread should be unlocked before signalling the condition
-    // or wxThreadModule::OnExit() would deadlock
-    wxMutexLocker locker( *gs_mutexDeleteThread );
-
     wxLogTrace(TRACE_THREADS, wxT("Thread %p auto deletes."), This->GetId());
 
     delete This;
 
+    // only lock gs_mutexDeleteThread after deleting the thread to avoid
+    // calling out into user code with it locked as this may result in
+    // deadlocks if the thread dtor deletes another thread (see #11501)
+    wxMutexLocker locker( *gs_mutexDeleteThread );
+
     wxCHECK_RET( gs_nThreadsBeingDeleted > 0,
                  wxT("no threads scheduled for deletion, yet we delete one?") );