summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-03-28 13:28:39 (GMT)
committerGitHub <noreply@github.com>2024-03-28 13:28:39 (GMT)
commit8dbfdb2957a7baade3a88661517f163ad694c39f (patch)
treef7e3fb2c352d0bb618d9965fec0a795227a3c307 /Python/pystate.c
parent9a1e55b8c5723206116f7016921be3937ef2f4e5 (diff)
downloadcpython-8dbfdb2957a7baade3a88661517f163ad694c39f.zip
cpython-8dbfdb2957a7baade3a88661517f163ad694c39f.tar.gz
cpython-8dbfdb2957a7baade3a88661517f163ad694c39f.tar.bz2
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.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 921e74e..8489f53 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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) {