diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-11 17:33:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-11 17:33:08 (GMT) |
commit | 82a18069a1c288b9be3cdaf63a04e4c77fbd231f (patch) | |
tree | 219c98c62906504ef043217f78c027dccef95683 /Include/internal/pycore_pystate.h | |
parent | 9297a72dbd39aca99fa8cf92960ce1869bc51c0b (diff) | |
download | cpython-82a18069a1c288b9be3cdaf63a04e4c77fbd231f.zip cpython-82a18069a1c288b9be3cdaf63a04e4c77fbd231f.tar.gz cpython-82a18069a1c288b9be3cdaf63a04e4c77fbd231f.tar.bz2 |
[3.11] gh-108987: Fix _thread.start_new_thread() race condition (#109135) (#109272)
gh-108987: Fix _thread.start_new_thread() race condition (#109135)
Fix _thread.start_new_thread() race condition. If a thread is created
during Python finalization, the newly spawned thread now exits
immediately instead of trying to access freed memory and lead to a
crash.
thread_run() calls PyEval_AcquireThread() which checks if the thread
must exit. The problem was that tstate was dereferenced earlier in
_PyThreadState_Bind() which leads to a crash most of the time.
Move _PyThreadState_CheckConsistency() from thread_run() to
_PyThreadState_Bind().
(cherry picked from commit 517cd82ea7d01b344804413ef05610934a43a241)
Diffstat (limited to 'Include/internal/pycore_pystate.h')
-rw-r--r-- | Include/internal/pycore_pystate.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index 8696aaf..7c5aba1 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -65,6 +65,8 @@ _Py_ThreadCanHandlePendingCalls(void) extern int _PyThreadState_CheckConsistency(PyThreadState *tstate); #endif +int _PyThreadState_MustExit(PyThreadState *tstate); + /* Variable and macro for in-line access to current thread and interpreter state */ |