[Stackless] Is this me, or stackless?
Richard Tew
richard.m.tew at gmail.com
Sat Jul 8 23:52:31 CEST 2006
On 7/8/06, Richard Tew <richard.m.tew at gmail.com> wrote:
> I tried a preliminary fix, which was to make a main tasklet
> and make it the current one before Stackless tried to kill all the
> remaining ones, but tasklets seemed to be run rather than
> killed.
Here's a patch that fixes the problem. Anyone want to
take a look and give a second opinion before I check it in?
Index: stacklesseval.c
===================================================================
--- stacklesseval.c (revision 47131)
+++ stacklesseval.c (working copy)
@@ -290,7 +290,8 @@
while (1) {
PyCStackObject *csfirst = slp_cstack_chain, *cs;
- PyTaskletObject *t;
+ PyTaskletObject *t, *task;
+ PyTaskletObject **chain;
if (csfirst == NULL)
break;
@@ -310,6 +311,26 @@
t = cs->task;
Py_INCREF(t);
+ /* We need to ensure that the tasklet 't' is in the scheduler
+ * tasklet chain before this one (our main). This ensures
+ * that this one is directly switched back to after 't' is
+ * killed. The reason we do this this is because if another
+ * tasklet is switched to, this is of course it being scheduled
+ * and run. Why we do not need to do this for tasklets blocked
+ * on channels is that when they are scheduled to be run and
+ * killed, they will be implicitly placed before this one,
+ * leaving it to run next.
+ */
+ if (!t->flags.blocked) {
+ chain = &t;
+ SLP_CHAIN_REMOVE(PyTaskletObject, chain, task, next, prev)
+ chain = &cs->tstate->st.main;
+ task = cs->task;
+ SLP_CHAIN_INSERT(PyTaskletObject, chain, task, next, prev);
+ cs->tstate->st.current = cs->tstate->st.main;
+ t = cs->task;
+ }
+
PyTasklet_Kill(t);
PyErr_Clear();
@@ -321,10 +342,13 @@
}
}
+int initialize_main_and_current();
+
void PyStackless_kill_tasks_with_stacks(int allthreads)
{
PyThreadState *ts = PyThreadState_Get();
+ initialize_main_and_current();
slp_kill_tasks_with_stacks(allthreads ? NULL : ts);
}
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list