mirror of
https://github.com/python/cpython.git
synced 2025-10-20 00:13:47 +00:00
gh-137400: Fix thread-safety issues when profiling all threads (gh-137518)
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.
This commit is contained in:
parent
923d68655b
commit
a10152f8fd
11 changed files with 431 additions and 241 deletions
|
@ -1183,9 +1183,10 @@ sys__settraceallthreads(PyObject *module, PyObject *arg)
|
|||
argument = arg;
|
||||
}
|
||||
|
||||
|
||||
PyEval_SetTraceAllThreads(func, argument);
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (_PyEval_SetTraceAllThreads(interp, func, argument) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
@ -1263,8 +1264,10 @@ sys__setprofileallthreads(PyObject *module, PyObject *arg)
|
|||
argument = arg;
|
||||
}
|
||||
|
||||
PyEval_SetProfileAllThreads(func, argument);
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (_PyEval_SetProfileAllThreads(interp, func, argument) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue