Received: from eggs.gnu.org ([2001:4830:134:3::10]:35316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVHYF-0005Jb-IH for qemu-devel@nongnu.org; Tue, 10 Mar 2015 06:38:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVHYE-0002tl-Lo for qemu-devel@nongnu.org; Tue, 10 Mar 2015 06:38:15 -0400 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]:35067) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVHYE-0002tg-Fj for qemu-devel@nongnu.org; Tue, 10 Mar 2015 06:38:14 -0400 Received: by wibbs8 with SMTP id bs8so28945185wib.0 for ; Tue, 10 Mar 2015 03:38:13 -0700 (PDT) Received: from localhost.localdomain (net-188-216-23-124.cust.vodafonedsl.it. [188.216.23.124]) by mx.google.com with ESMTPSA id fs8sm19653201wib.8.2015.03.10.03.38.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Mar 2015 03:38:12 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 10 Mar 2015 11:37:53 +0100 Message-Id: <1425983880-26906-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1425983880-26906-1-git-send-email-pbonzini@redhat.com> References: <1425983880-26906-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 04/11] qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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