[pypy-commit] pypy default: Fix a race condition in PyEval_SaveThread, when called for the *first* time

amauryfa noreply at buildbot.pypy.org
Sat Sep 15 21:16:35 CEST 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r57358:9bf06ba21208
Date: 2012-09-15 21:12 +0200
http://bitbucket.org/pypy/pypy/changeset/9bf06ba21208/

Log:	Fix a race condition in PyEval_SaveThread, when called for the
	*first* time in a multi-threaded environment.

diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py
--- a/pypy/module/cpyext/pystate.py
+++ b/pypy/module/cpyext/pystate.py
@@ -23,10 +23,10 @@
     the current thread must have acquired it.  (This function is available even
     when thread support is disabled at compile time.)"""
     state = space.fromcache(InterpreterState)
+    tstate = state.swap_thread_state(
+        space, lltype.nullptr(PyThreadState.TO))
     if rffi.aroundstate.before:
         rffi.aroundstate.before()
-    tstate = state.swap_thread_state(
-        space, lltype.nullptr(PyThreadState.TO))
     return tstate
 
 @cpython_api([PyThreadState], lltype.Void)


More information about the pypy-commit mailing list