]> granicus.if.org Git - python/commitdiff
Issue #11393: New try to fix faulthandler_thread()
authorVictor Stinner <victor.stinner@haypocalc.com>
Fri, 1 Apr 2011 01:00:05 +0000 (03:00 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Fri, 1 Apr 2011 01:00:05 +0000 (03:00 +0200)
Always release the cancel join.

Fix also another corner case: _PyFaulthandler_Fini() called after setting
running variable to zero, but before releasing the join lock.

Modules/faulthandler.c

index 760689e7815b44bf7b404daa9b60ac6766f88012..f8b9fb663977a7169ae5bdf6ccc084f97b8b0a85 100644 (file)
@@ -401,7 +401,6 @@ faulthandler_thread(void *unused)
                                          thread.timeout_ms, 0);
         if (st == PY_LOCK_ACQUIRED) {
             /* Cancelled by user */
-            PyThread_release_lock(thread.cancel_event);
             break;
         }
         /* Timeout => dump traceback */
@@ -418,8 +417,9 @@ faulthandler_thread(void *unused)
     } while (ok && thread.repeat);
 
     /* The only way out */
-    thread.running = 0;
+    PyThread_release_lock(thread.cancel_event);
     PyThread_release_lock(thread.join_event);
+    thread.running = 0;
 }
 
 static void
@@ -428,11 +428,11 @@ faulthandler_cancel_dump_tracebacks_later(void)
     if (thread.running) {
         /* Notify cancellation */
         PyThread_release_lock(thread.cancel_event);
-        /* Wait for thread to join */
-        PyThread_acquire_lock(thread.join_event, 1);
-        assert(thread.running == 0);
-        PyThread_release_lock(thread.join_event);
     }
+    /* Wait for thread to join */
+    PyThread_acquire_lock(thread.join_event, 1);
+    assert(thread.running == 0);
+    PyThread_release_lock(thread.join_event);
     Py_CLEAR(thread.file);
 }