How to release the GIL from C?

Roger Binns rogerb at rogerbinns.com
Wed May 23 20:00:52 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Roger Binns wrote:
> I am trying to release the GIL in a multi-threaded program (efforts
> detailed below) without any success.

The ultimate cause was that the program forked to go into daemon mode.
I had called PyOS_AfterFork() as the documents directed.  What I hadn't
realised (and isn't documented) is that AfterFork() reinitialises the
Python threading state by making a new GIL and acquires it.  The
acquiring bit meant none of my other threads could ever get it.

It is still unclear from the docs exactly which combination of functions
dealing with threadstate, threads and lock you need to call to just
unilaterally give up the GIL (ie when you don't have following block
that wants to reacquire the GIL)

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGVNW0mOOfHg372QQRAuyOAJ4pCCIK779XgvaUdKBtSa+nHElrHQCgiueP
n/0uMFCSH3SrQhMXdm2Jb/o=
=uh4D
-----END PGP SIGNATURE-----



More information about the Python-list mailing list