[pypy-dev] GIL hacks in pypy

Timothy Baldridge tbaldridge at gmail.com
Fri Jan 13 18:58:27 CET 2012

So I guess the next question would be, how does the GIL actually work
in PyPy. Let's say you have two threads running jitted code. Does a
jitted code loop run one, release the GIL, acquire, run again, etc? In
CPython the GIL is released every X number of bytecodes, but jitted
code doesn't have bytecodes, so what is the level of cooperation
there? Is the jitted code littered with cooperative "release-lock"



On Fri, Jan 13, 2012 at 11:35 AM, Armin Rigo <arigo at tunes.org> wrote:
> Hi Timothy,
> On Fri, Jan 13, 2012 at 16:37, Timothy Baldridge <tbaldridge at gmail.com> wrote:
>> But in CPython we
>> can do this ugly little hack for getting "free" locks where you
>> basically set the GIL "remaining" bytecodes count to 32 billion,
>> execute your code, then return it to the original value.
> Bah!  That's a hack indeed.
> I think the cleanest solution would be to write the compare-and-swap
> operation as C code in CPython, and as RPython code in PyPy.
> Otherwise, I'm unsure about getting compare-and-swap, but you can
> definitely do some atomic operations using lists or dicts.
> A bientôt,
> Armin.

“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

More information about the pypy-dev mailing list