mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +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
|
@ -579,9 +579,8 @@ PyEval_ReleaseThread(PyThreadState *tstate)
|
|||
}
|
||||
|
||||
#ifdef HAVE_FORK
|
||||
/* This function is called from PyOS_AfterFork_Child to destroy all threads
|
||||
which are not running in the child process, and clear internal locks
|
||||
which might be held by those threads. */
|
||||
/* This function is called from PyOS_AfterFork_Child to re-initialize the
|
||||
GIL and pending calls lock. */
|
||||
PyStatus
|
||||
_PyEval_ReInitThreads(PyThreadState *tstate)
|
||||
{
|
||||
|
@ -598,8 +597,6 @@ _PyEval_ReInitThreads(PyThreadState *tstate)
|
|||
struct _pending_calls *pending = &tstate->interp->ceval.pending;
|
||||
_PyMutex_at_fork_reinit(&pending->mutex);
|
||||
|
||||
/* Destroy all threads except the current one */
|
||||
_PyThreadState_DeleteExcept(tstate);
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue