mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Close #19576: PyGILState_Ensure() now initializes threads. At startup, Python
has no concrete GIL. If PyGILState_Ensure() is called from a new thread for the first time and PyEval_InitThreads() was not called yet, a GIL needs to be created.
This commit is contained in:
parent
56668dc187
commit
62ca10051b
2 changed files with 10 additions and 0 deletions
|
@ -771,6 +771,11 @@ PyGILState_Ensure(void)
|
|||
assert(autoInterpreterState); /* Py_Initialize() hasn't been called! */
|
||||
tcur = (PyThreadState *)PyThread_get_key_value(autoTLSkey);
|
||||
if (tcur == NULL) {
|
||||
/* At startup, Python has no concrete GIL. If PyGILState_Ensure() is
|
||||
called from a new thread for the first time, we need the create the
|
||||
GIL. */
|
||||
PyEval_InitThreads();
|
||||
|
||||
/* Create a new thread state for this thread */
|
||||
tcur = PyThreadState_New(autoInterpreterState);
|
||||
if (tcur == NULL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue