mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.13] gh-137400: Fix thread-safety issues when profiling all threads (gh-137518) (gh-137733)
There were a few thread-safety issues when profiling or tracing all
threads via PyEval_SetProfileAllThreads or PyEval_SetTraceAllThreads:
* The loop over thread states could crash if a thread exits concurrently
(in both the free threading and default build)
* The modification of `c_profilefunc` and `c_tracefunc` wasn't
thread-safe on the free threading build.
(cherry picked from commit a10152f8fd)
This commit is contained in:
parent
f6186a3709
commit
16d2e97cf3
12 changed files with 29814 additions and 29714 deletions
10
Python/generated_cases.c.h
generated
10
Python/generated_cases.c.h
generated
|
|
@ -5151,7 +5151,15 @@
|
|||
_Py_CODEUNIT *this_instr = next_instr - 1;
|
||||
(void)this_instr;
|
||||
assert(frame == tstate->current_frame);
|
||||
if (tstate->tracing == 0) {
|
||||
#ifdef Py_GIL_DISABLED
|
||||
// For thread-safety, we need to check instrumentation version
|
||||
// even when tracing. Otherwise, another thread may concurrently
|
||||
// re-write the bytecode while we are executing this function.
|
||||
int check_instrumentation = 1;
|
||||
#else
|
||||
int check_instrumentation = (tstate->tracing == 0);
|
||||
#endif
|
||||
if (check_instrumentation) {
|
||||
uintptr_t global_version =
|
||||
_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) &
|
||||
~_PY_EVAL_EVENTS_MASK;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue