diff options
author | Sam Gross <colesbury@gmail.com> | 2024-03-21 18:21:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-21 18:21:02 (GMT) |
commit | 1f72fb5447ef3f8892b4a7a6213522579c618e8e (patch) | |
tree | 43997f5d50ff319adc557320b277a68ddf38099d /Modules/posixmodule.c | |
parent | 50369e6c34d05222e5a0ec9443a9f7b230e83112 (diff) | |
download | cpython-1f72fb5447ef3f8892b4a7a6213522579c618e8e.zip cpython-1f72fb5447ef3f8892b4a7a6213522579c618e8e.tar.gz cpython-1f72fb5447ef3f8892b4a7a6213522579c618e8e.tar.bz2 |
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.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 8867916..a4b635e 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -664,6 +664,14 @@ PyOS_AfterFork_Child(void) goto fatal_error; } + // Remove the dead thread states. We "start the world" once we are the only + // thread state left to undo the stop the world call in `PyOS_BeforeFork`. + // That needs to happen before `_PyThreadState_DeleteList`, because that + // may call destructors. + PyThreadState *list = _PyThreadState_RemoveExcept(tstate); + _PyEval_StartTheWorldAll(&_PyRuntime); + _PyThreadState_DeleteList(list); + status = _PyImport_ReInitLock(tstate->interp); if (_PyStatus_EXCEPTION(status)) { goto fatal_error; |