completely new barrier implementation, addressing major correctness issues
authorRich Felker <dalias@aerifal.cx>
Sat, 7 May 2011 00:00:59 +0000 (20:00 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 7 May 2011 00:00:59 +0000 (20:00 -0400)
commitf16a3089be33a75ef8e75b2dd5ec3095996bbb87
tree24bf14e183f0e29993b07a9508ce5bd44c4ad2bb
parent202911435b56fe007ca62fc6e573fa3ea238d337
completely new barrier implementation, addressing major correctness issues

the previous implementation had at least 2 problems:

1. the case where additional threads reached the barrier before the
first wave was finished leaving the barrier was untested and seemed
not to be working.

2. threads leaving the barrier continued to access memory within the
barrier object after other threads had successfully returned from
pthread_barrier_wait. this could lead to memory corruption or crashes
if the barrier object had automatic storage in one of the waiting
threads and went out of scope before all threads finished returning,
or if one thread unmapped the memory in which the barrier object
lived.

the new implementation avoids both problems by making the barrier
state essentially local to the first thread which enters the barrier
wait, and forces that thread to be the last to return.
src/internal/pthread_impl.h
src/thread/pthread_barrier_wait.c