]> Git Repo - qemu.git/commitdiff
qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK
authorPaolo Bonzini <[email protected]>
Thu, 5 Mar 2015 15:47:14 +0000 (16:47 +0100)
committerPaolo Bonzini <[email protected]>
Tue, 10 Mar 2015 09:49:25 +0000 (10:49 +0100)
PTHREAD_MUTEX_ERRORCHECK is completely broken with respect to fork.
The way to safely do fork is to bring all threads to a quiescent
state by acquiring locks (either in callers---as we do for the
iothread mutex---or using pthread_atfork's prepare callbacks)
and then release them in the child.

The problem is that releasing error-checking locks in the child
fails under glibc with EPERM, because the mutex stores a different
owner tid than the duplicated thread in the child process.  We
could make it work for locks acquired via pthread_atfork, by
recreating the mutex in the child instead of unlocking it
(we know that there are no other threads that could have taken
the mutex; but when the lock is acquired in fork's caller
that would not be possible.

The simplest solution is just to forgo error checking.

Signed-off-by: Paolo Bonzini <[email protected]>
util/qemu-thread-posix.c

index 50a29d8f7aad7fe5882ba33d18dce4b7bf2ccb97..ba67cec62bfcb9fc27e04ace2f6f274c39d713ad 100644 (file)
@@ -51,12 +51,8 @@ static void error_exit(int err, const char *msg)
 void qemu_mutex_init(QemuMutex *mutex)
 {
     int err;
-    pthread_mutexattr_t mutexattr;
 
-    pthread_mutexattr_init(&mutexattr);
-    pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK);
-    err = pthread_mutex_init(&mutex->lock, &mutexattr);
-    pthread_mutexattr_destroy(&mutexattr);
+    err = pthread_mutex_init(&mutex->lock, NULL);
     if (err)
         error_exit(err, __func__);
 }
This page took 0.023984 seconds and 4 git commands to generate.