Previous | Next --- Slide 23 of 29
Back to Lecture Thumbnails

It avoids the deadlock problem in the last slide by clear flag after all thread leave.


This solves the deadlock by having "while (b->leave_counter != P);". This works as the first arriving thread to the next barrier can only wait and switch the flag only when all the threads have left the previous block. This solves the problem of the implementation a slide ago which had some slow threads stuck behind the last barrier but cannot make progress because of the faster threads switching the flag before the slower threads have left the last barrier.