diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-03-03 23:20:25 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-03-03 23:20:25 (GMT) |
commit | 71fb87e64c51627564262fd64299f7ac79625404 (patch) | |
tree | df72f580ff07a3bd5419e3a3509a8c5806a51836 /Modules | |
parent | 2379bb664ac33b77d076a9a8db59f73af9eb3c8f (diff) | |
download | cpython-71fb87e64c51627564262fd64299f7ac79625404.zip cpython-71fb87e64c51627564262fd64299f7ac79625404.tar.gz cpython-71fb87e64c51627564262fd64299f7ac79625404.tar.bz2 |
Issue #7544: Preallocate thread memory before creating the thread to avoid a
fatal error in low memory condition.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/threadmodule.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c index b65360e..6494f49 100644 --- a/Modules/threadmodule.c +++ b/Modules/threadmodule.c @@ -428,6 +428,7 @@ struct bootstate { PyObject *func; PyObject *args; PyObject *keyw; + PyThreadState *tstate; }; static void @@ -437,8 +438,9 @@ t_bootstrap(void *boot_raw) PyThreadState *tstate; PyObject *res; - tstate = PyThreadState_New(boot->interp); - + tstate = boot->tstate; + tstate->thread_id = PyThread_get_thread_ident(); + _PyThreadState_Init(tstate); PyEval_AcquireThread(tstate); nb_threads++; res = PyEval_CallObjectWithKeywords( @@ -503,6 +505,11 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) boot->func = func; boot->args = args; boot->keyw = keyw; + boot->tstate = _PyThreadState_Prealloc(boot->interp); + if (boot->tstate == NULL) { + PyMem_DEL(boot); + return PyErr_NoMemory(); + } Py_INCREF(func); Py_INCREF(args); Py_XINCREF(keyw); @@ -513,6 +520,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) Py_DECREF(func); Py_DECREF(args); Py_XDECREF(keyw); + PyThreadState_Clear(boot->tstate); PyMem_DEL(boot); return NULL; } |