Author: Armin Rigo <[email protected]>
Branch:
Changeset: r59117:e4d1e11dfbd9
Date: 2012-11-28 15:53 -0800
http://bitbucket.org/pypy/pypy/changeset/e4d1e11dfbd9/
Log: Issue 1323: don't use the PTHREAD_*_INITIALIZER macros. They might
initialize the mutexes and condition variables, but after a fork(),
on some systems, these become completely broken. Instead, always
assume they contain garbage and initialize them properly.
This fixes test_threading.test_3_join_in_forked_from_thread on OS/X.
diff --git a/pypy/translator/c/src/thread_pthread.c
b/pypy/translator/c/src/thread_pthread.c
--- a/pypy/translator/c/src/thread_pthread.c
+++ b/pypy/translator/c/src/thread_pthread.c
@@ -421,8 +421,8 @@
}
static volatile long pending_acquires = -1;
-static pthread_mutex_t mutex_gil = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t cond_gil = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t mutex_gil;
+static pthread_cond_t cond_gil;
static void assert_has_the_gil(void)
{
@@ -434,11 +434,23 @@
long RPyGilAllocate(void)
{
+ int status, error = 0;
_debug_print("RPyGilAllocate\n");
- pending_acquires = 0;
- pthread_mutex_trylock(&mutex_gil);
- assert_has_the_gil();
- return 1;
+ pending_acquires = -1;
+
+ status = pthread_mutex_init(&mutex_gil,
+ pthread_mutexattr_default);
+ CHECK_STATUS("pthread_mutex_init[GIL]");
+
+ status = pthread_cond_init(&cond_gil,
+ pthread_condattr_default);
+ CHECK_STATUS("pthread_cond_init[GIL]");
+
+ if (error == 0) {
+ pending_acquires = 0;
+ RPyGilAcquire();
+ }
+ return (error == 0);
}
long RPyGilYieldThread(void)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit