Author JunyiXie
Recipients JunyiXie, vstinner
Date 2021-06-10.10:14:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1623320092.73.0.0769901058138.issue44374@roundup.psfhosted.org>
In-reply-to
Content
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
2021-06-10 10:14:52JunyiXiesetrecipients: + JunyiXie, vstinner
2021-06-10 10:14:52JunyiXiesetmessageid: <1623320092.73.0.0769901058138.issue44374@roundup.psfhosted.org>
2021-06-10 10:14:52JunyiXielinkissue44374 messages
2021-06-10 10:14:51JunyiXiecreate