mirror of
https://github.com/python/cpython.git
synced 2025-11-10 02:21:40 +00:00
[3.14] gh-136870: fix data race in PyThreadState_Clear on sys_tracing_threads (GH-136951) (#136953)
gh-136870: fix data race in `PyThreadState_Clear` on `sys_tracing_threads` (GH-136951)
In free-threading, multiple threads can be cleared concurrently as such the modifications on `sys_tracing_threads` should be done while holding the profile lock, otherwise it can race with other threads setting up profiling.
(cherry picked from commit f183996eb7)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
893707c538
commit
718fc5b139
1 changed files with 9 additions and 0 deletions
|
|
@ -1793,6 +1793,10 @@ PyThreadState_Clear(PyThreadState *tstate)
|
|||
"PyThreadState_Clear: warning: thread still has a generator\n");
|
||||
}
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
PyMutex_Lock(&_PyRuntime.ceval.sys_trace_profile_mutex);
|
||||
#endif
|
||||
|
||||
if (tstate->c_profilefunc != NULL) {
|
||||
tstate->interp->sys_profiling_threads--;
|
||||
tstate->c_profilefunc = NULL;
|
||||
|
|
@ -1801,6 +1805,11 @@ PyThreadState_Clear(PyThreadState *tstate)
|
|||
tstate->interp->sys_tracing_threads--;
|
||||
tstate->c_tracefunc = NULL;
|
||||
}
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
PyMutex_Unlock(&_PyRuntime.ceval.sys_trace_profile_mutex);
|
||||
#endif
|
||||
|
||||
Py_CLEAR(tstate->c_profileobj);
|
||||
Py_CLEAR(tstate->c_traceobj);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue