{ Bounded buffer with multiple producers and consumers }

var
  InE, OutE: TEventCount; { Set up and initially 0 }
  PrTk, CnTk: TSequencer; { Set up and initially 0 }

{ producer }

var
  MyTurn: integer;

begin
  while not terminated do
  begin
    MyTurn := PrTk.Ticket;
    InE.Await(MyTurn);
    OutE.Await(MyTurn - N + 1);
    { insert item at myturn mod N }
    InE.Advance;
  end;
end;

{ consumer }

var
  MyTurn: integer;

begin
  while not terminated do
  begin
    MyTurn := CnTk.Ticket;
    OutE.Await(MyTurn);
    InE.Await(MyTurn + 1);
    { remove item at MyTurn mod N }
    OutE.Advance;
  end;
end;