On slide 38, b->flag == 1 means that none of the processes are in a barrier, and b->flag == 0 means that at least one process is in a barrier.
Now on this slide, b->flag == private_sense means that the process is not in a barrier, and b->flag != private_sense means that the process is in a barrier. This fixes the problem of a process passing through two barriers because the value of private_sense switches every time we enter a barrier.
bochet
num_arrived is not used in Barrier, so can be removed.
private_sense = 1 - private_sense is more intuitive for flipping between 0 and 1.
hweetvpu
Because private_sense is private to each thread, a barrier is completely finished iff every thread/processor sees b.flag == private_sense. Moreover, since private_sense is not flipped until the owner thread hits the next barrier, this guarantees that all threads will be able to finish a barrier.
Bye
I wonder if anything affecting correctness of the program will happen if I only use one unlock(b->lock) before the if statement in this case?
manishj
@Bye Nice observation, I also don't see any problem in releasing the lock before the
if statement.
On slide 38,
b->flag == 1
means that none of the processes are in a barrier, andb->flag == 0
means that at least one process is in a barrier.Now on this slide,
b->flag == private_sense
means that the process is not in a barrier, andb->flag != private_sense
means that the process is in a barrier. This fixes the problem of a process passing through two barriers because the value of private_sense switches every time we enter a barrier.num_arrived
is not used in Barrier, so can be removed.private_sense = 1 - private_sense
is more intuitive for flipping between 0 and 1.Because private_sense is private to each thread, a barrier is completely finished iff every thread/processor sees
b.flag == private_sense
. Moreover, sinceprivate_sense
is not flipped until the owner thread hits the next barrier, this guarantees that all threads will be able to finish a barrier.I wonder if anything affecting correctness of the program will happen if I only use one unlock(b->lock) before the if statement in this case?
@Bye Nice observation, I also don't see any problem in releasing the lock before the if statement.