with Text_IO, Ada.Integer_Text_IO; use Text_IO, Ada.Integer_Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Float_Text_IO; use Ada.Float_Text_IO; procedure Turns is task type Broker(N:Integer) is -- N is number of tasks to synchronize entry Synch; entry WaitQ; end Broker; task body Broker is Val :Integer := 0; -- zero means no tasks has called synch Stop : Boolean := False; -- controls server loop -- Reset : Boolean := False; CX : Integer := N; begin while not(Stop) loop select accept Synch do if (Val accept WaitQ do CX := CX-1; end WaitQ; end select; if (CX=0) then -- reset Val := 0; CX := N; end if; end loop; end Broker; Brk : Broker(3); -- shared broker task task type Runner(Id:Integer); task body Runner is X : Integer := 0; begin while (X<10) loop Brk.Synch; Put(Id,Width=>2); Put(" Synched, X is "); Put(X,Width=>2); New_Line; delay(1.0*Id); -- delay X := X+1; end loop; end Runner; R1 : Runner(0); R2 : Runner(1); R3 : Runner(2); begin -- main task null; end Turns;