procedure main()
// How many threads have arrived to the barrier
shared count := 0
// Protects the increment of the count
shared can_access_count := create_semaphore(1)
// Locked (0) until all threads arrive, then it is unlocked (1)
shared barrier := create_semaphore(0)
// Read thread count from standard input
input shared const thread_count
// Create a thread team running secondary
create_threads(thread_count, secondary)
end procedure
procedure secondary()
Statement A
// Adapt rendezvous solution here
wait(can_access_count)
count := count + 1
if count = thread_count then
for index := 0 to thread_count do
signal(barrier)
end for
end if
signal(can_access_count)
wait(barrier)
// Statement B can be only executed until all threads have run Statement A
Statement B
end procedure