In the previous slide, we only keep track of the number of threads that enter into the barrier, which can cause deadlock. One way to solve this is to keep track of two variables, one which denotes the number of threads that have entered, and another that denotes the number of threads that have left. This way threads that enter into the second barrier can wait until all threads have exited the first barrier.
This comment was marked helpful 0 times.
bwasti
Note the lock on line 15 and 17 is actually b->lock. A key point is that the while (b->leave_counter != P) relinquishes the lock before it does any checking and then is able to get the lock back before it sets the flag to 0. This ensures that every other thread is not within the process of updating leave_counter and we have guaranteed every thread has left.
This comment was marked helpful 0 times.
bxb
Another way of looking at these barrier implementations is that the flag exists as the actual "barrier" that stalls processors until every processor has reached that point. What this solution and the one of the following slide presents are ways of controlling this flag so that it has the desired behavior.
This comment was marked helpful 0 times.
ron
Line 21 should be int arrived = ++(b->arrive_counter).
In the previous slide, we only keep track of the number of threads that enter into the barrier, which can cause deadlock. One way to solve this is to keep track of two variables, one which denotes the number of threads that have entered, and another that denotes the number of threads that have left. This way threads that enter into the second barrier can wait until all threads have exited the first barrier.
This comment was marked helpful 0 times.
Note the
lock
on line 15 and 17 is actuallyb->lock
. A key point is that thewhile (b->leave_counter != P)
relinquishes the lock before it does any checking and then is able to get the lock back before it sets the flag to 0. This ensures that every other thread is not within the process of updatingleave_counter
and we have guaranteed every thread has left.This comment was marked helpful 0 times.
Another way of looking at these barrier implementations is that the flag exists as the actual "barrier" that stalls processors until every processor has reached that point. What this solution and the one of the following slide presents are ways of controlling this flag so that it has the desired behavior.
This comment was marked helpful 0 times.
Line 21 should be
int arrived = ++(b->arrive_counter)
.This comment was marked helpful 0 times.