Commit 1c76b7f5 authored by Victor Stinner's avatar Victor Stinner

Issue #11393: Fix faulthandler_thread(): release cancel lock before join lock

If the thread releases the join lock before the cancel lock, the thread may
sometimes still be alive at cancel_dump_tracebacks_later() exit. So the cancel
lock may be destroyed while the thread is still alive, whereas the thread will
try to release the cancel lock, which just crash.

Another minor fix: the thread doesn't release the cancel lock if it didn't
acquire it.
parent d6056b7d
...@@ -401,6 +401,7 @@ faulthandler_thread(void *unused) ...@@ -401,6 +401,7 @@ faulthandler_thread(void *unused)
thread.timeout_ms, 0); thread.timeout_ms, 0);
if (st == PY_LOCK_ACQUIRED) { if (st == PY_LOCK_ACQUIRED) {
/* Cancelled by user */ /* Cancelled by user */
PyThread_release_lock(thread.cancel_event);
break; break;
} }
/* Timeout => dump traceback */ /* Timeout => dump traceback */
...@@ -419,7 +420,6 @@ faulthandler_thread(void *unused) ...@@ -419,7 +420,6 @@ faulthandler_thread(void *unused)
/* The only way out */ /* The only way out */
thread.running = 0; thread.running = 0;
PyThread_release_lock(thread.join_event); PyThread_release_lock(thread.join_event);
PyThread_release_lock(thread.cancel_event);
} }
static void static void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment