with GNAT.Bounded_Buffers; with Ada.Text_IO; use Ada.Text_IO; procedure Demo_Buffers is type Job is new Integer; -- for example Stop : constant Job := -1; -- arbitrary package Jobs is new GNAT.Bounded_Buffers (Job); Buffer_Size : constant := 20; -- arbitrary Iterations : constant := Buffer_Size * 3; -- arbitrary -- we want to insert more items than the buffer can -- hold at one time to ensure that the condition -- synchonization is exercised Buffer : Jobs.Bounded_Buffer (Capacity => Buffer_Size, Ceiling => Jobs.Default_Ceiling); task Producer; task Consumer; task body Producer is begin for K in Job range 1 .. Iterations loop -- do some work to produce the next value; -- in this case we just insert the loop parameter -- ... Buffer.Insert (K); -- ... -- do some more work -- ... end loop; Buffer.Insert (Stop); end Producer; task body Consumer is Next : Job; begin loop Buffer.Remove (Next); exit when Next = Stop; -- process the next job ... Put_Line (Next'Img); -- for example Flush; end loop; end Consumer; begin null; end Demo_Buffers;