@@ -1751,7 +1751,7 @@ decrement_stoptheworld_countdown(struct _stoptheworld_state *stw);
1751
1751
1752
1752
/* Common code for PyThreadState_Delete() and PyThreadState_DeleteCurrent() */
1753
1753
static void
1754
- tstate_delete_common (PyThreadState * tstate )
1754
+ tstate_delete_common (PyThreadState * tstate , int release_gil )
1755
1755
{
1756
1756
assert (tstate -> _status .cleared && !tstate -> _status .finalized );
1757
1757
tstate_verify_not_active (tstate );
@@ -1793,10 +1793,6 @@ tstate_delete_common(PyThreadState *tstate)
1793
1793
1794
1794
HEAD_UNLOCK (runtime );
1795
1795
1796
- #ifdef Py_GIL_DISABLED
1797
- _Py_qsbr_unregister (tstate );
1798
- #endif
1799
-
1800
1796
// XXX Unbind in PyThreadState_Clear(), or earlier
1801
1797
// (and assert not-equal here)?
1802
1798
if (tstate -> _status .bound_gilstate ) {
@@ -1807,6 +1803,14 @@ tstate_delete_common(PyThreadState *tstate)
1807
1803
// XXX Move to PyThreadState_Clear()?
1808
1804
clear_datastack (tstate );
1809
1805
1806
+ if (release_gil ) {
1807
+ _PyEval_ReleaseLock (tstate -> interp , tstate , 1 );
1808
+ }
1809
+
1810
+ #ifdef Py_GIL_DISABLED
1811
+ _Py_qsbr_unregister (tstate );
1812
+ #endif
1813
+
1810
1814
tstate -> _status .finalized = 1 ;
1811
1815
}
1812
1816
@@ -1818,7 +1822,7 @@ zapthreads(PyInterpreterState *interp)
1818
1822
when the threads are all really dead (XXX famous last words). */
1819
1823
while ((tstate = interp -> threads .head ) != NULL ) {
1820
1824
tstate_verify_not_active (tstate );
1821
- tstate_delete_common (tstate );
1825
+ tstate_delete_common (tstate , 0 );
1822
1826
free_threadstate ((_PyThreadStateImpl * )tstate );
1823
1827
}
1824
1828
}
@@ -1829,7 +1833,7 @@ PyThreadState_Delete(PyThreadState *tstate)
1829
1833
{
1830
1834
_Py_EnsureTstateNotNULL (tstate );
1831
1835
tstate_verify_not_active (tstate );
1832
- tstate_delete_common (tstate );
1836
+ tstate_delete_common (tstate , 0 );
1833
1837
free_threadstate ((_PyThreadStateImpl * )tstate );
1834
1838
}
1835
1839
@@ -1842,8 +1846,7 @@ _PyThreadState_DeleteCurrent(PyThreadState *tstate)
1842
1846
_Py_qsbr_detach (((_PyThreadStateImpl * )tstate )-> qsbr );
1843
1847
#endif
1844
1848
current_fast_clear (tstate -> interp -> runtime );
1845
- tstate_delete_common (tstate );
1846
- _PyEval_ReleaseLock (tstate -> interp , tstate , 1 );
1849
+ tstate_delete_common (tstate , 1 ); // release GIL as part of call
1847
1850
free_threadstate ((_PyThreadStateImpl * )tstate );
1848
1851
}
1849
1852
0 commit comments