[pypy-dev] Question about stm_descriptor_init(), tasklets and OS threads

Armin Rigo arigo at tunes.org
Thu May 10 09:41:30 CEST 2012


Hi Andrew,

Please look at the latest documentation:
https://bitbucket.org/pypy/pypy/raw/stm-thread/pypy/doc/stm.rst

You should be able to use such a "thread.atomic" in stackless.py.  You
need to create N threads and run the tasklets in these threads.  As
long as each tasklet's user code is protected by a "thread.atomic",
then they will *appear* to be run serially.

You probably need to call "thread.atomic.__enter__" and "__exit__"
explicitly for your use case; if you do, then I could also move the
functionality as normal built-in method.  You also have to handle
issues like tasklets not being always allowed to switch threads.

As a first approximation, on CPython you can implement a dummy
"thread.atomic" by acquiring and releasing a single lock.  It is only
an approximative equivalent because other non-atomic threads will be
allowed to run concurrently; but for this kind of experiment where
*all* threads should be "atomic", it should not make a difference.


A bientôt,

Armin.


More information about the pypy-dev mailing list