public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix pthread_barrier_wait on !i?86 !x86_64
@ 2004-02-20 17:23 Jakub Jelinek
  2004-02-20 20:19 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2004-02-20 17:23 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

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  <jakub@redhat.com>

	* 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix pthread_barrier_wait on !i?86 !x86_64
  2004-02-20 17:23 [PATCH] Fix pthread_barrier_wait on !i?86 !x86_64 Jakub Jelinek
@ 2004-02-20 20:19 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2004-02-20 20:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

Applied.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-02-20 20:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-20 17:23 [PATCH] Fix pthread_barrier_wait on !i?86 !x86_64 Jakub Jelinek
2004-02-20 20:19 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).