barrier:
return record of
count := 0
mutex := semaphore(1)
turnstile1 := semaphore(0)
turnstile2 := semaphore(1)
wait(barrier):
barrier_phase1(barrier)
barrier_phase2(barrier)
barrier_phase1(barrier):
wait(mutex)
if ++count == thread_count then
wait(turnstile2)
signal(turnstile1)
signal(mutex)
wait(turnstile1)
signal(turnstile1)
barrier_phase2(barrier):
wait(mutex)
if --count == 0 then
wait(turnstile1)
signal(turnstile2)
signal(mutex)
wait(turnstile2)
signal(turnstile2)
main:
shared thread_count := read_integer()
shared my_barrier := barrier(thread_count)
create_thread(secondary, thread_count)
secondary:
while true do
Sentence A
barrier_phase1(my_barrier)
Sentence B
barrier_phase2(my_barrier)
third:
for row := 0 to row_count do
process_row()
wait(mybarrier)