[Stackless] Stackless runtime smacking into GIL while a callback is running

Jeff Senn senn at maya.com
Mon Mar 12 16:00:54 CET 2012

I believe what Richard meant is: if a tasklet has references to resources buried in it's "saved C-stack state" (which of course may go back to where it started)
unexpected things may happen as the tasklet executes -- especially if it suddenly finds itself on another thread.

I don' t think the tasklet *necessarily* references anything troubling -- though clearly there could be bugs...

The internals, in the case of multiple threads starting tasklets, are subtle, and not the most tested aspect of Stackless.

That said: those of us who have tried to work around possible bugs have found some success in limiting the exposure
of the tasklet mechanism to multithreading by keeping tasklet creation and execution confined in a particular thread.
e.g. you might create a thread-safe queue of python objects representing "potential" tasklets that a single thread is then popping to 
create and execute the *actual* tasklets.  Even if this is not a perfect solution for you, it may lead to finding race-conditions
or reference errors in the code on the boundary of C++ and Python...

I, also, could not tell what exactly you were doing from your email...so I'm not sure whether this is a helpful suggestion or not.


On Mar 12, 2012, at 10:32 AM, Adam Preble wrote:

> On Mon, Mar 12, 2012 at 12:20 AM, Richard Tew <richard.m.tew at gmail.com> wrote:
> On Mon, Mar 12, 2012 at 8:28 AM, Adam Preble <adam.preble at gmail.com> wrote:
> > I'm assuming that somehow Stackless didn't get the memo that I stole the
> > interpreter for a moment for another thread.  Is there some special rules I
> > need to honor with it when I do this crazy stuff?
> The one key thing with respect to Stackless to keep in mind, is that
> tasklets may be composed out of parts of the thread they were created
> on.  This means that if you try and run them on another thread.. I'm
> not sure what happens.  Is it possible that is your problem?  I find
> it a little hard to get a grasp on what you are doing, and exactly
> what problem arises from reading your email unfortunately.
> I suppose we should get into the programming legalese of "may be composed." Is that "must?" I am basically doing what you're pondering I'm doing.  The declaration of the class happens in the bringup code of the thread that starts Python and has the Python interpreter.  The callback arrives from a thread in the C++ runtime.  I suppose since it's enough of a mystery problem, I can try to doodle something up that's easier to show on pastebin or something.  
> I would be dismayed if this were the problem.  From what I could tell, if I acquired the GIL in conventional Python, then I was in the clear.  What would be my alternative then for Stackless?
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20120312/8ca56180/attachment.html>

More information about the Stackless mailing list