Skip to content

Commit ac58a16

Browse files
committed
Fix existing thread-safety issue with interp_has_threads().
1 parent 811ca19 commit ac58a16

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Python/pylifecycle.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,13 +2236,13 @@ interp_has_threads(PyInterpreterState *interp)
22362236
return 0;
22372237
}
22382238

2239-
// We don't have to worry about locking this because the
2240-
// world is stopped.
2239+
HEAD_LOCK(interp->runtime);
22412240
_Py_FOR_EACH_TSTATE_UNLOCKED(interp, tstate) {
22422241
if (tstate->_whence == _PyThreadState_WHENCE_THREADING) {
22432242
return 1;
22442243
}
22452244
}
2245+
HEAD_UNLOCK(interp->runtime);
22462246

22472247
return 0;
22482248
}
@@ -2314,6 +2314,8 @@ make_pre_finalization_calls(PyThreadState *tstate, int subinterpreters)
23142314
finalize_subinterpreters();
23152315
}
23162316

2317+
2318+
23172319
/* Stop the world to prevent other threads from creating threads or
23182320
* atexit callbacks. On the default build, this is simply locked by
23192321
* the GIL. For pending calls, we acquire the dedicated mutex, because

0 commit comments

Comments
 (0)