Previous | Next --- Slide 39 of 44
Back to Lecture Thumbnails
bochet

The idea here is we use a leave_counter to make sure all processors leave from previous barrier before starting a new barrier. It avoids the problem in previous slide: some early processor leaves early, starts a new barrier and traps the rest processors.

Also notice the unlock/lock in the else part.

preritrodney

Shouldn't (P) be (P-1) as one thread is waiting for all other (P-1) threads to proceed before exiting the barrier?

manishj

num_arrived variable stores the number of threads arrived till now. And it is the duty of the last thread to notify rest of the (P-1) threads to leave the barrier. So, the value should be P only.

preritrodney

@manishj The first arriving thread will actually be looping waiting for b->leave_counter to become P which will never happen as it itself is one of the P threads.