[3.13] gh-154175: Fetch _PY_GIL_DROP_REQUEST_BIT under GIL by cmaloney · Pull Request #157013 · python/cpython · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Python/ceval_gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,16 @@ drop_gil(PyInterpreterState *interp, PyThreadState *tstate, int final_release)
Py_FatalError("drop_gil: GIL is not locked");
}

int drop_requested = 0;
if (!final_release) {
/* Sub-interpreter support: threads might have been switched
under our feet using PyThreadState_Swap(). Fix the GIL last
holder variable so that our heuristics work. */
_Py_atomic_store_ptr_relaxed(&gil->last_holder, tstate);

/* Checked here as tstate may freed outside gil. */
drop_requested = _Py_eval_breaker_bit_is_set(tstate,
_PY_GIL_DROP_REQUEST_BIT);
}

drop_gil_impl(tstate, gil);
Expand All @@ -262,8 +267,7 @@ drop_gil(PyInterpreterState *interp, PyThreadState *tstate, int final_release)
crash. We can use final_release to indicate the thread is done with the
GIL, and that's the only time we might delete the interpreter. See
https://github.com/python/cpython/issues/104341. */
if (!final_release &&
_Py_eval_breaker_bit_is_set(tstate, _PY_GIL_DROP_REQUEST_BIT)) {
if (!final_release && drop_requested) {
MUTEX_LOCK(gil->switch_mutex);
/* Not switched yet => wait */
if (((PyThreadState*)_Py_atomic_load_ptr_relaxed(&gil->last_holder)) == tstate)
Expand Down
3 changes: 0 additions & 3 deletions Tools/tsan/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
race:get_allocator_unlocked
race:set_allocator_unlocked

# gh-124878: race condition when interpreter finalized while daemon thread runs
race:free_threadstate

# https://gist.github.com/mpage/daaf32b39180c1989572957b943eb665
thread:pthread_create
3 changes: 0 additions & 3 deletions Tools/tsan/suppressions_free_threading.txt
Loading