[pypy-commit] pypy default: Aaargh again. Borked the locking here. Shows up as a rare crash

arigo pypy.commits at gmail.com
Mon Sep 26 05:44:59 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r87392:c540b2c9656a
Date: 2016-09-26 10:53 +0100
http://bitbucket.org/pypy/pypy/changeset/c540b2c9656a/

Log:	Aaargh again. Borked the locking here. Shows up as a rare crash in
	test_lib_pypy/cffi_tests/embedding/test_thread.

diff --git a/rpython/translator/c/src/threadlocal.c b/rpython/translator/c/src/threadlocal.c
--- a/rpython/translator/c/src/threadlocal.c
+++ b/rpython/translator/c/src/threadlocal.c
@@ -15,9 +15,10 @@
 static int check_valid(void);
 
 void _RPython_ThreadLocals_Acquire(void) {
-    while (!pypy_lock_test_and_set(&pypy_threadlocal_lock, 1)) {
-        /* busy loop */
-    }
+    long old_value;
+    do {
+        old_value = pypy_lock_test_and_set(&pypy_threadlocal_lock, 1);
+    } while (old_value != 0);   /* busy loop */
     assert(check_valid());
 }
 void _RPython_ThreadLocals_Release(void) {


More information about the pypy-commit mailing list