Skip to content

Commit

Permalink
Issue python#120: Correctly grab the head_mutex, fix grafting error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Anselm Kruis committed Apr 9, 2017
1 parent aa9559b commit ae1d0a4
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions Stackless/core/stacklesseval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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.
Expand Down

0 comments on commit ae1d0a4

Please sign in to comment.