protected type Barrier is procedure Arrive; private entry Go; -- used to delay early arrivals count : Integer := 0; -- number who have arrived time_to_leave : Boolean := False; end Barrier; protected body Barrier is procedure Arrive is begin count := count+1; if count < N then requeue Go; -- wait for others to arrive else count := count-1; time_to_leave := True; end if; end; entry Go when time_to_leave is begin count := count-1; if count = 0 then time_to_leave := False; end if; end; end Barrier;