This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyThreadState_IsCurrent bug under building Python with --with-experimental-isolated-subinterpreters
Type: Stage:
Components: Subinterpreters Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: JunyiXie, vstinner
Priority: normal Keywords:

Created on 2021-06-10 10:14 by JunyiXie, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg395517 - (view) Author: junyixie (JunyiXie) * Date: 2021-06-10 10:14
under building Python with --with-experimental-isolated-subinterpreters
PyThreadState_IsCurrent use _PyRuntime.gilstate. is shared by multi sub interpreters.
Use interpreter `gil->last_holder == state` can fix it? 



```
static int
PyThreadState_IsCurrent(PyThreadState *tstate)
{
    /* Must be the tstate for this thread */
    struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
    assert(_PyGILState_GetThisThreadState(gilstate) == tstate);
    return tstate == _PyRuntimeGILState_GetThreadState(gilstate);
}
```


```
static int
PyThreadState_IsCurrent(PyThreadState *tstate)
{
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
    PyInterpreterState *interp = tstate->interp;
    struct _ceval_state *ceval2 = &interp->ceval;
    struct _gil_runtime_state *gil = &ceval2->gil;
    return tstate == (PyThreadState*)_Py_atomic_load_relaxed(&gil->last_holder);
#else
    /* Must be the tstate for this thread */
    struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
    assert(_PyGILState_GetThisThreadState(gilstate) == tstate);
    return tstate == _PyRuntimeGILState_GetThreadState(gilstate);
#endif
}
```
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88540
2021-06-10 10:14:52JunyiXiecreate