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

Adam Preble adam.preble at gmail.com
Mon Mar 12 17:07:04 CET 2012


On Mon, Mar 12, 2012 at 10:00 AM, Jeff Senn <senn at maya.com> wrote:

>
> 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...
>
> Is this queue itself in Python or C++?  I wasn't clear on that and I can
imagine that would matter a little bit.


> 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.
>
>
I'm going to try some stuff tonight, and perhaps start trying to type up an
example so everybody has something to munge on.  It's non-trivial though so
it's not the kind of thing I can just slap together real quick, so that's
why I started with a rambly email.  Of particular note in the code I wrote
was that I wasn't really taking advantage of Stackless Python in it (yet).

Anyways I had a thought about what might be wrong, but I'm not sure what I
can do about it.  Let's say when one of my C++ threads does the callback,
I'm toggling a boolean value in a Python object.  That Python object was
created prior in the original Python thread.  In that original thread, it
is basically spinning in a loop on that bool.  When the foreign thread
touches the bool, do I invite myself to trouble?  I can get away with
horrors like that in C++ since bools are just value types and cross-core
cache coherency protocols will get the memo across eventually; but I wonder
in PythonLand--where everything is a reference--if that is a smart thing to
try to do.  I was assuming that by grabbing the GIL I was in control but
maybe that's not safe.  Or perhaps worse still in the Stackless context
switch stuff, the bool would get mashed up.

So I wonder, if I used a channel instead would that be a safe resource for
communicating across two literal threads, versus just two green threads?

Anyways I think I owe the distribution some code so I'll start pounding
away on that in the evening (CST).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20120312/b90a5cf6/attachment.html>


More information about the Stackless mailing list