summaryrefslogtreecommitdiffstats
path: root/Include/internal/pycore_interp.h
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-09-27 19:41:06 (GMT)
committerGitHub <noreply@github.com>2023-09-27 19:41:06 (GMT)
commit32466c97c06ee5812923d695195394c736eeb707 (patch)
treee5de52c5dcc30067c6cd79fa97b66d104f911ea4 /Include/internal/pycore_interp.h
parentf49958c886a2f2608f1008186d588efc2a98b445 (diff)
downloadcpython-32466c97c06ee5812923d695195394c736eeb707.zip
cpython-32466c97c06ee5812923d695195394c736eeb707.tar.gz
cpython-32466c97c06ee5812923d695195394c736eeb707.tar.bz2
gh-109793: Allow Switching Interpreters During Finalization (gh-109794)
Essentially, we should check the thread ID rather than the thread state pointer.
Diffstat (limited to 'Include/internal/pycore_interp.h')
-rw-r--r--Include/internal/pycore_interp.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h
index ba5764e..0912bd1 100644
--- a/Include/internal/pycore_interp.h
+++ b/Include/internal/pycore_interp.h
@@ -93,6 +93,8 @@ struct _is {
and _PyInterpreterState_SetFinalizing()
to access it, don't access it directly. */
_Py_atomic_address _finalizing;
+ /* The ID of the OS thread in which we are finalizing. */
+ unsigned long _finalizing_id;
struct _gc_runtime_state gc;
@@ -215,9 +217,23 @@ _PyInterpreterState_GetFinalizing(PyInterpreterState *interp) {
return (PyThreadState*)_Py_atomic_load_relaxed(&interp->_finalizing);
}
+static inline unsigned long
+_PyInterpreterState_GetFinalizingID(PyInterpreterState *interp) {
+ return _Py_atomic_load_ulong_relaxed(&interp->_finalizing_id);
+}
+
static inline void
_PyInterpreterState_SetFinalizing(PyInterpreterState *interp, PyThreadState *tstate) {
_Py_atomic_store_relaxed(&interp->_finalizing, (uintptr_t)tstate);
+ if (tstate == NULL) {
+ _Py_atomic_store_ulong_relaxed(&interp->_finalizing_id, 0);
+ }
+ else {
+ // XXX Re-enable this assert once gh-109860 is fixed.
+ //assert(tstate->thread_id == PyThread_get_thread_ident());
+ _Py_atomic_store_ulong_relaxed(&interp->_finalizing_id,
+ tstate->thread_id);
+ }
}