[3.12] gh-109793: Allow Switching Interpreters During Finalization (gh-109794) by ericsnowcurrently · Pull Request #110705 · python/cpython
/* The ID of the OS thread in which we are finalizing. We use _Py_atomic_address instead of adding a new _Py_atomic_ulong. */ _Py_atomic_address _finalizing_id; /* The value to use for sys.path[0] in new subinterpreters. Normally this would be part of the PyConfig struct. However, we cannot add it there in 3.12 since that's an ABI change. */
static inline unsigned long _PyRuntimeState_GetFinalizingID(_PyRuntimeState *runtime) { return (unsigned long)_Py_atomic_load_relaxed(&runtime->_finalizing_id); }
static inline void _PyRuntimeState_SetFinalizing(_PyRuntimeState *runtime, PyThreadState *tstate) { _Py_atomic_store_relaxed(&runtime->_finalizing, (uintptr_t)tstate); if (tstate == NULL) { _Py_atomic_store_relaxed(&runtime->_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_relaxed(&runtime->_finalizing_id, (uintptr_t)tstate->thread_id); } }
#ifdef __cplusplus