[New-bugs-announce] [issue44374] PyThreadState_IsCurrent bug under building Python with --with-experimental-isolated-subinterpreters

junyixie report at bugs.python.org
Thu Jun 10 06:14:52 EDT 2021


New submission from junyixie <xie.junyi at outlook.com>:

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
}
```

----------
components: Subinterpreters
messages: 395517
nosy: JunyiXie, vstinner
priority: normal
severity: normal
status: open
title: PyThreadState_IsCurrent bug under building Python with --with-experimental-isolated-subinterpreters
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44374>
_______________________________________


More information about the New-bugs-announce mailing list