gh-110481: Fix biased reference counting queue initialization. (#117271)

The biased reference counting queue must be initialized from the bound
(active) thread because it uses `_Py_ThreadId()` as the key in a hash
table.
This commit is contained in:
Sam Gross 2024-03-28 09:28:39 -04:00 committed by GitHub
parent 9a1e55b8c5
commit 8dbfdb2957
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View file

@ -261,6 +261,12 @@ bind_tstate(PyThreadState *tstate)
tstate->native_thread_id = PyThread_get_thread_native_id();
#endif
#ifdef Py_GIL_DISABLED
// Initialize biased reference counting inter-thread queue. Note that this
// needs to be initialized from the active thread.
_Py_brc_init_thread(tstate);
#endif
// mimalloc state needs to be initialized from the active thread.
tstate_mimalloc_bind(tstate);
@ -1412,10 +1418,6 @@ init_threadstate(_PyThreadStateImpl *_tstate,
tstate->what_event = -1;
tstate->previous_executor = NULL;
#ifdef Py_GIL_DISABLED
// Initialize biased reference counting inter-thread queue
_Py_brc_init_thread(tstate);
#endif
llist_init(&_tstate->mem_free_queue);
if (interp->stoptheworld.requested || _PyRuntime.stoptheworld.requested) {