[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 04/11] qemu-thread: do not use PTHREAD_MUTEX_ERRORCHE
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 04/11] qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK |
Date: |
Tue, 10 Mar 2015 11:37:53 +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 <address@hidden>
---
util/qemu-thread-posix.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index 50a29d8..ba67cec 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -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__);
}
--
2.3.0
- [Qemu-devel] [PULL 00/11] scsi, RCU, KVM, x86 changes for 2015-03-10, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 01/11] iscsi: Fix check for username, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 03/11] kvm_stat: add kvm_stat.1 man page, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 04/11] qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK,
Paolo Bonzini <=
- [Qemu-devel] [PULL 05/11] rcu: handle forks safely, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 08/11] hw: Propagate errors through qdev_prop_set_drive(), Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 06/11] cpus: initialize cpu->memory_dispatch, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 02/11] kvm_stat: add column headers to text UI, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 09/11] scsi: Improve error reporting for invalid drive property, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 07/11] scsi: Clean up duplicated error in legacy if=scsi code, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 11/11] x86: fix SS selector in SYSRET, Paolo Bonzini, 2015/03/10
- [Qemu-devel] [PULL 10/11] scsi: Convert remaining PCI HBAs to realize(), Paolo Bonzini, 2015/03/10
- Re: [Qemu-devel] [PULL 00/11] scsi, RCU, KVM, x86 changes for 2015-03-10, Peter Maydell, 2015/03/10