From ae1d0a410443418fa990b189ed7c9a9cb44eaac2 Mon Sep 17 00:00:00 2001 From: Anselm Kruis Date: Sun, 9 Apr 2017 16:37:42 +0200 Subject: [PATCH] Issue #120: Correctly grab the head_mutex, fix grafting error This commit fixes a regression introduced by commit fc13eecdd0ad. When I grafted the patch for this issue from branch 2.7-slp (1fb75d58a), I forgot to remove a 2.7-slp only part of the code. In effect, this change reapplies commit b8a8122bbb91. https://bitbucket.org/stackless-dev/stackless/issues/120 --- Stackless/core/stacklesseval.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/Stackless/core/stacklesseval.c b/Stackless/core/stacklesseval.c index dead57be07682c..fde9bff5cfa842 100644 --- a/Stackless/core/stacklesseval.c +++ b/Stackless/core/stacklesseval.c @@ -619,7 +619,6 @@ void slp_kill_tasks_with_stacks(PyThreadState *target_ts) */ if (target_ts == NULL && tasklet_list) { PyThreadState *ts; - PyObject *threadid_list = NULL; count = 0; /* build a list of tasklets to be killed */ @@ -636,30 +635,9 @@ void slp_kill_tasks_with_stacks(PyThreadState *target_ts) } SLP_HEAD_UNLOCK(); - /* get the list of thread ids */ - if (PyExc_TaskletExit) - threadid_list = slp_getthreads(Py_None); /* requires the HEAD lock */ - /* kill the tasklets */ kill_pending(tasklet_list); - /* kill the threads */ - if (threadid_list != NULL) { - Py_ssize_t i, len; - assert(PyList_CheckExact(threadid_list)); - len = PyList_GET_SIZE(threadid_list); - for (i=0; i < len; i++) { - long thread_id; - PyObject *item = PyList_GET_ITEM(threadid_list, i); - assert(PyLong_CheckExact(item)); - thread_id = PyLong_AsLong(item); - if (thread_id != cts->thread_id) { - /* requires the HEAD lock */ - PyThreadState_SetAsyncExc(thread_id, PyExc_TaskletExit); - PyErr_Clear(); - } - } - Py_DECREF(threadid_list); - } + /* We must not release the GIL while we might hold the HEAD-lock. * Otherwise another thread (usually the thread of the killed tasklet) * could try to get the HEAD lock. The result would be a wonderful dead lock.