[Python-Dev] Threading and callbacks - missing documentation (original) (raw)

Thomas Heller thomas.heller@ion-tof.com
Fri, 12 Apr 2002 19:58:42 +0200


From: "Martin v. Loewis" <martin@v.loewis.de>

"Thomas Heller" <thomas.heller@ion-tof.com> writes:

> Can't you at least partly combine the advantages of 1 and 2 by using > thread local storage for the global variable? I have no idea if there > is a portable way to do this... That would work, but, as you already guess: there is no portable way to do this. If you can accept platform-specific code, this is a good idea. [in another message] The pthreads equivalent of Windows TLS is pthreadgetspecific/setspecific, so you could cover pthreads and Win32.

Normally I don't care too much about portable code, but in this case (storing and retriving the current threadstate between calls to C code and callbacks from C-code into Python code) the most benefits could only be gained if the Python core and hopefully also extension developers cooperated and used this method.

Maybe the Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS macros could be changed to store the threadstate in a global TLS area for Windows and pthreads platforms?

Thomas