Skip to content

Commit 3e40135

Browse files
committed
Add locks around the loop
1 parent f5daefe commit 3e40135

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Python/ceval.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
#define _Py_atomic_load_relaxed_int32(ATOMIC_VAL) _Py_atomic_load_relaxed(ATOMIC_VAL)
9999
#endif
100100

101+
#define HEAD_LOCK(runtime) \
102+
PyThread_acquire_lock((runtime)->interpreters.mutex, WAIT_LOCK)
103+
#define HEAD_UNLOCK(runtime) \
104+
PyThread_release_lock((runtime)->interpreters.mutex)
101105

102106
/* Forward declarations */
103107
static PyObject *trace_call_function(
@@ -7038,12 +7042,19 @@ PyEval_SetProfileAllThreads(Py_tracefunc func, PyObject *arg)
70387042
{
70397043
PyThreadState *this_tstate = _PyThreadState_GET();
70407044
PyInterpreterState* interp = this_tstate->interp;
7045+
7046+
_PyRuntimeState *runtime = &_PyRuntime;
7047+
HEAD_LOCK(runtime);
70417048
PyThreadState* ts = PyInterpreterState_ThreadHead(interp);
7049+
HEAD_UNLOCK(runtime);
7050+
70427051
while (ts) {
70437052
if (_PyEval_SetProfile(ts, func, arg) < 0) {
70447053
_PyErr_WriteUnraisableMsg("in PyEval_SetProfileAllThreads", NULL);
70457054
}
7055+
HEAD_LOCK(runtime);
70467056
ts = PyThreadState_Next(ts);
7057+
HEAD_UNLOCK(runtime);
70477058
}
70487059
}
70497060

@@ -7105,12 +7116,19 @@ PyEval_SetTraceAllThreads(Py_tracefunc func, PyObject *arg)
71057116
{
71067117
PyThreadState *this_tstate = _PyThreadState_GET();
71077118
PyInterpreterState* interp = this_tstate->interp;
7119+
7120+
_PyRuntimeState *runtime = &_PyRuntime;
7121+
HEAD_LOCK(runtime);
71087122
PyThreadState* ts = PyInterpreterState_ThreadHead(interp);
7123+
HEAD_UNLOCK(runtime);
7124+
71097125
while (ts) {
71107126
if (_PyEval_SetTrace(ts, func, arg) < 0) {
71117127
_PyErr_WriteUnraisableMsg("in PyEval_SetTraceAllThreads", NULL);
71127128
}
7129+
HEAD_LOCK(runtime);
71137130
ts = PyThreadState_Next(ts);
7131+
HEAD_UNLOCK(runtime);
71147132
}
71157133
}
71167134

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy