Skip to content

gh-115103: Fix unregistering of QSBR state #116480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2024
Merged
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
10 changes: 7 additions & 3 deletions Python/qsbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,17 @@ _Py_qsbr_register(_PyThreadStateImpl *tstate, PyInterpreterState *interp,
void
_Py_qsbr_unregister(_PyThreadStateImpl *tstate)
{
struct _qsbr_shared *shared = tstate->qsbr->shared;

PyMutex_Lock(&shared->mutex);
// NOTE: we must load (or reload) the thread state's qbsr inside the mutex
// because the array may have been resized (changing tstate->qsbr) while
// we waited to acquire the mutex.
struct _qsbr_thread_state *qsbr = tstate->qsbr;
struct _qsbr_shared *shared = qsbr->shared;

assert(qsbr->seq == 0 && "thread state must be detached");

PyMutex_Lock(&shared->mutex);
assert(qsbr->allocated && qsbr->tstate == (PyThreadState *)tstate);

tstate->qsbr = NULL;
qsbr->tstate = NULL;
qsbr->allocated = false;
Expand Down