@@ -176,13 +176,11 @@ ThreadHandle_get_os_handle(ThreadHandle *handle, PyThread_handle_t *os_handle)
176176}
177177
178178static void
179- add_to_shutdown_handles (thread_module_state * state , ThreadHandle * handle , PyInterpreterState * interp )
179+ add_to_shutdown_handles (thread_module_state * state , ThreadHandle * handle )
180180{
181- _PyRWMutex_RLock (& interp -> prefini_mutex );
182181 HEAD_LOCK (& _PyRuntime );
183182 llist_insert_tail (& state -> shutdown_handles , & handle -> shutdown_node );
184183 HEAD_UNLOCK (& _PyRuntime );
185- _PyRWMutex_RUnlock (& interp -> prefini_mutex );
186184}
187185
188186static void
@@ -197,16 +195,13 @@ clear_shutdown_handles(thread_module_state *state)
197195}
198196
199197static void
200- remove_from_shutdown_handles (ThreadHandle * handle , PyInterpreterState * interp )
198+ remove_from_shutdown_handles (ThreadHandle * handle )
201199{
202- assert (interp != NULL );
203- _PyRWMutex_RLock (& interp -> prefini_mutex );
204200 HEAD_LOCK (& _PyRuntime );
205201 if (handle -> shutdown_node .next != NULL ) {
206202 llist_remove (& handle -> shutdown_node );
207203 }
208204 HEAD_UNLOCK (& _PyRuntime );
209- _PyRWMutex_RUnlock (& interp -> prefini_mutex );
210205}
211206
212207static ThreadHandle *
@@ -314,7 +309,7 @@ _PyThread_AfterFork(struct _pythread_runtime_state *state)
314309 handle -> mutex = (PyMutex ){_Py_UNLOCKED };
315310 _PyEvent_Notify (& handle -> thread_is_exiting );
316311 llist_remove (node );
317- remove_from_shutdown_handles (handle , _PyInterpreterState_GET () );
312+ remove_from_shutdown_handles (handle );
318313 }
319314}
320315
@@ -347,7 +342,6 @@ thread_run(void *boot_raw)
347342{
348343 struct bootstate * boot = (struct bootstate * ) boot_raw ;
349344 PyThreadState * tstate = boot -> tstate ;
350- PyInterpreterState * interp = tstate -> interp ;
351345
352346 // Wait until the handle is marked as running
353347 PyEvent_Wait (& boot -> handle_ready );
@@ -374,7 +368,7 @@ thread_run(void *boot_raw)
374368
375369 _PyThreadState_Bind (tstate );
376370 PyEval_AcquireThread (tstate );
377- _Py_atomic_add_ssize (& interp -> threads .count , 1 );
371+ _Py_atomic_add_ssize (& tstate -> interp -> threads .count , 1 );
378372
379373 PyObject * res = PyObject_Call (boot -> func , boot -> args , boot -> kwargs );
380374 if (res == NULL ) {
@@ -392,13 +386,13 @@ thread_run(void *boot_raw)
392386
393387 thread_bootstate_free (boot , 1 );
394388
395- _Py_atomic_add_ssize (& interp -> threads .count , -1 );
389+ _Py_atomic_add_ssize (& tstate -> interp -> threads .count , -1 );
396390 PyThreadState_Clear (tstate );
397391 _PyThreadState_DeleteCurrent (tstate );
398392
399393exit :
400394 // Don't need to wait for this thread anymore
401- remove_from_shutdown_handles (handle , interp );
395+ remove_from_shutdown_handles (handle );
402396
403397 _PyEvent_Notify (& handle -> thread_is_exiting );
404398 ThreadHandle_decref (handle );
@@ -1877,12 +1871,12 @@ do_start_new_thread(thread_module_state *state, PyObject *func, PyObject *args,
18771871 // Add the handle before starting the thread to avoid adding a handle
18781872 // to a thread that has already finished (i.e. if the thread finishes
18791873 // before the call to `ThreadHandle_start()` below returns).
1880- add_to_shutdown_handles (state , handle , interp );
1874+ add_to_shutdown_handles (state , handle );
18811875 }
18821876
18831877 if (ThreadHandle_start (handle , func , args , kwargs ) < 0 ) {
18841878 if (!daemon ) {
1885- remove_from_shutdown_handles (handle , interp );
1879+ remove_from_shutdown_handles (handle );
18861880 }
18871881 return -1 ;
18881882 }
0 commit comments