mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
gh-105699: Use a _Py_hashtable_t for the PyModuleDef Cache (gh-106974)
This fixes a crasher due to a race condition, triggered infrequently when two isolated (own GIL) subinterpreters simultaneously initialize their sys or builtins modules. The crash happened due the combination of the "detached" thread state we were using and the "last holder" logic we use for the GIL. It turns out it's tricky to use the same thread state for different threads. Who could have guessed? We solve the problem by eliminating the one object we were still sharing between interpreters. We replace it with a low-level hashtable, using the "raw" allocator to avoid tying it to the main interpreter. We also remove the accommodations for "detached" thread states, which were a dubious idea to start with.
This commit is contained in:
parent
55ed85e49c
commit
8ba4df91ae
5 changed files with 129 additions and 191 deletions
|
|
@ -125,11 +125,6 @@ extern PyThreadState * _PyThreadState_New(PyInterpreterState *interp);
|
|||
extern void _PyThreadState_Bind(PyThreadState *tstate);
|
||||
extern void _PyThreadState_DeleteExcept(PyThreadState *tstate);
|
||||
|
||||
extern void _PyThreadState_InitDetached(PyThreadState *, PyInterpreterState *);
|
||||
extern void _PyThreadState_ClearDetached(PyThreadState *);
|
||||
extern void _PyThreadState_BindDetached(PyThreadState *);
|
||||
extern void _PyThreadState_UnbindDetached(PyThreadState *);
|
||||
|
||||
// Export for '_testinternalcapi' shared extension
|
||||
PyAPI_FUNC(PyObject*) _PyThreadState_GetDict(PyThreadState *tstate);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue