Skip to content

Commit c20f566

Browse files
committed
Improve thread safety in _PyThread_AfterFork by preserving not-started handles
1 parent a66bae8 commit c20f566

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Modules/_threadmodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ _PyThread_AfterFork(struct _pythread_runtime_state *state)
296296
continue;
297297
}
298298

299+
// keep not_start handles – they are safe to start in the child
300+
if (handle->state == THREAD_HANDLE_NOT_STARTED){
301+
continue;
302+
}
303+
299304
// Mark all threads as done. Any attempts to join or detach the
300305
// underlying OS thread (if any) could crash. We are the only thread;
301306
// it's safe to set this non-atomically.

0 commit comments

Comments
 (0)