mirror of
https://github.com/python/cpython.git
synced 2025-10-19 16:03:42 +00:00
gh-140257: fix data race on eval_breaker during finalization (#140265)
This commit is contained in:
parent
78e1d65a4d
commit
c8729c9909
2 changed files with 6 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
|||
Fix data race between interpreter_clear() and take_gil() on eval_breaker
|
||||
during finalization with daemon threads.
|
|
@ -763,10 +763,11 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
|
|||
|
||||
Py_CLEAR(interp->audit_hooks);
|
||||
|
||||
// At this time, all the threads should be cleared so we don't need atomic
|
||||
// operations for instrumentation_version or eval_breaker.
|
||||
// gh-140257: Threads have already been cleared, but daemon threads may
|
||||
// still access eval_breaker atomically via take_gil() right before they
|
||||
// hang. Use an atomic store to prevent data races during finalization.
|
||||
interp->ceval.instrumentation_version = 0;
|
||||
tstate->eval_breaker = 0;
|
||||
_Py_atomic_store_uintptr(&tstate->eval_breaker, 0);
|
||||
|
||||
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
|
||||
interp->monitors.tools[i] = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue