mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-109793: Allow Switching Interpreters During Finalization (gh-109794)
Essentially, we should check the thread ID rather than the thread state pointer.
This commit is contained in:
parent
f49958c886
commit
32466c97c0
7 changed files with 96 additions and 3 deletions
|
@ -171,6 +171,8 @@ typedef struct pyruntimestate {
|
|||
Use _PyRuntimeState_GetFinalizing() and _PyRuntimeState_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 pyinterpreters {
|
||||
PyThread_type_lock mutex;
|
||||
|
@ -303,9 +305,23 @@ _PyRuntimeState_GetFinalizing(_PyRuntimeState *runtime) {
|
|||
return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->_finalizing);
|
||||
}
|
||||
|
||||
static inline unsigned long
|
||||
_PyRuntimeState_GetFinalizingID(_PyRuntimeState *runtime) {
|
||||
return _Py_atomic_load_ulong_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_ulong_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_ulong_relaxed(&runtime->_finalizing_id,
|
||||
tstate->thread_id);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue