mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +00:00
gh-116522: Refactor _PyThreadState_DeleteExcept
(#117131)
Split `_PyThreadState_DeleteExcept` into two functions: - `_PyThreadState_RemoveExcept` removes all thread states other than one passed as an argument. It returns the removed thread states as a linked list. - `_PyThreadState_DeleteList` deletes those dead thread states. It may call destructors, so we want to "start the world" before calling `_PyThreadState_DeleteList` to avoid potential deadlocks.
This commit is contained in:
parent
50369e6c34
commit
1f72fb5447
5 changed files with 41 additions and 23 deletions
|
@ -1934,8 +1934,11 @@ Py_FinalizeEx(void)
|
|||
will be called in the current Python thread. Since
|
||||
_PyRuntimeState_SetFinalizing() has been called, no other Python thread
|
||||
can take the GIL at this point: if they try, they will exit
|
||||
immediately. */
|
||||
_PyThreadState_DeleteExcept(tstate);
|
||||
immediately. We start the world once we are the only thread state left,
|
||||
before we call destructors. */
|
||||
PyThreadState *list = _PyThreadState_RemoveExcept(tstate);
|
||||
_PyEval_StartTheWorldAll(runtime);
|
||||
_PyThreadState_DeleteList(list);
|
||||
|
||||
/* At this point no Python code should be running at all.
|
||||
The only thread state left should be the main thread of the main
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue