[pypy-issue] [issue1175] PyThread_{get, set, delete}_key_value should work without the GIL held

Marien Zwart tracker at bugs.pypy.org
Wed Jun 13 17:15:55 CEST 2012


New submission from Marien Zwart <marien.zwart at gmail.com>:

pyOpenSSL uses macros that store and retrieve the Python threadstate in
thread-local storage using PyThread_{get,set}_key_value, like this:

#  define MY_BEGIN_ALLOW_THREADS                                        \
    PyThread_delete_key_value(_pyOpenSSL_tstate_key);			\
    PyThread_set_key_value(_pyOpenSSL_tstate_key, PyEval_SaveThread());

/*
 * Get the previous Python threadstate and restore it.
 */
#  define MY_END_ALLOW_THREADS                                          \
    PyEval_RestoreThread(PyThread_get_key_value(_pyOpenSSL_tstate_key));

These assume PyThread_{get,set,delete}_key_value can be called without the GIL
held. That is the case in Python (its thread.c mentions this), but currently not
in PyPy: they deadlock as long as the GIL exists before the lock/unlock macros
are hit (at least one other thread has run).

Attaching some test code that demonstrates the problem (in pypy 1.9, at least).

----------
files: threadlock.c
messages: 4436
nosy: marienz, pypy-issue
priority: bug
release: 1.9
status: unread
title: PyThread_{get,set,delete}_key_value should work without the GIL held

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1175>
________________________________________


More information about the pypy-issue mailing list