From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23363 invoked by alias); 20 Feb 2004 17:23:15 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 23307 invoked from network); 20 Feb 2004 17:23:14 -0000 Received: from unknown (HELO sunsite.ms.mff.cuni.cz) (195.113.19.66) by sources.redhat.com with SMTP; 20 Feb 2004 17:23:14 -0000 Received: from sunsite.ms.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8) with ESMTP id i1KFEgvf002824; Fri, 20 Feb 2004 16:14:42 +0100 Received: (from jakub@localhost) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8/Submit) id i1KFEfKw002820; Fri, 20 Feb 2004 16:14:41 +0100 Date: Fri, 20 Feb 2004 17:23:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix pthread_barrier_wait on !i?86 !x86_64 Message-ID: <20040220151441.GZ4581@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2004-02/txt/msg00030.txt.bz2 Hi! The lock cannot be reacquired, otherwise it can deadlock (if the PTHREAD_BARRIER_SERIAL_THREAD thread returns without unlocking and the other try to reacquire the lock). i486+ and x86_64 assembly is already doing this, which is why it works. 2004-02-20 Jakub Jelinek * sysdeps/pthread/pthread_barrier_wait.c (pthread_barrier_wait): Release lock before the loop, don't reacquire it. * DESIGN-barrier.txt: Likewise. --- libc/nptl/sysdeps/pthread/pthread_barrier_wait.c.jj 2004-02-20 16:36:30.000000000 +0100 +++ libc/nptl/sysdeps/pthread/pthread_barrier_wait.c 2004-02-20 19:12:29.731215880 +0100 @@ -55,17 +55,13 @@ pthread_barrier_wait (barrier) /* The number of the event we are waiting for. The barrier's event number must be bumped before we continue. */ unsigned int event = ibarrier->curr_event; - do - { - /* Before suspending, make the barrier available to others. */ - lll_unlock (ibarrier->lock); - /* Wait for the event counter of the barrier to change. */ - lll_futex_wait (&ibarrier->curr_event, event); + /* Before suspending, make the barrier available to others. */ + lll_unlock (ibarrier->lock); - /* We are going to access shared data. */ - lll_lock (ibarrier->lock); - } + /* Wait for the event counter of the barrier to change. */ + do + lll_futex_wait (&ibarrier->curr_event, event); while (event == ibarrier->curr_event); } --- nptl/DESIGN-barrier.txt.jj 2004-02-19 17:50:39.000000000 +0100 +++ nptl/DESIGN-barrier.txt 2004-02-20 19:06:05.957558344 +0100 @@ -31,12 +31,9 @@ pthread_barrier_wait(barrier_t *barrier) result = BARRIER_SERIAL_THREAD; } else { event = barrier->curr_event; + lll_unlock(barrier->lock); do { - lll_unlock(barrier->lock); - futex_wait(&barrier->curr_event, event) - - lll_lock(barrier->lock); } while (event == barrier->curr_event); } Jakub