]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Close #19576: PyGILState_Ensure() now initializes threads. At startup, Python
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 13 Dec 2013 00:46:43 +0000 (01:46 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 13 Dec 2013 00:46:43 +0000 (01:46 +0100)
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.

Misc/NEWS
Python/pystate.c

index 2c1df0943ce33dcdc817537da9feba91bfe0faa7..84f36b8fee0a40bdcead84ad6be11da1f6365ae7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,11 @@ Release date: 2014-01-05
 Core and Builtins
 -----------------
 
+- Issue #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.
+
 - Issue #17576: Deprecation warning emitted now when __int__() or __index__()
   return not int instance.
 
index 6be71de2ae0be662b4048f5de6ebf49a72a01a8c..a56e3089694ec588a2fca1c4ff86b3350758628d 100644 (file)
@@ -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)