--
-- Version: @(#)shared.ada 1.1  Date: 5/30/84
--
--
-- Author:  Bryce Bardin
--          Ada Projects Section
--          Software Engineering Division
--          Ground Systems Group
--          Hughes Aircraft Company
--          Fullerton, CA
--


-- This program illustrates the use of tasking to provide shared access
-- to global variables.  N.B.:  The values it outputs may vary from run
-- to run depending on how tasking is implemented.
-- A "FIFO" solution to the READERS/WRITERS problem.
-- Authors:  Gerald Fisher and Robert Dewar.
-- (Modified by Bryce Bardin to terminate gracefully.)
-- May be used to provide shared access to objects by an arbitrary number of
-- readers and writers which are serviced in order from a single queue.
-- Writers are given uninterrupted access for updates and readers are assured
-- that updates are indivisible and therefore complete when read access is
-- granted.
--
-- If C is a task object of type Control and O is an object which is to be
-- shared between readers and writers using C, then:
--
--    readers should do:
--
--       C.Start(Read);
--       <read all or part of O>
--       C.Stop;
--
--    and writers should do:
--

--       C.Start(Write);
--       <update all or part of O>
--       C.Stop;
package Readers_Writers is

    type Service is (Read, Write);

    task type Control is
        entry Start (Mode : Service);  -- start readers or writers
        entry Stop;                    -- stop readers or writers
    end Control;

end Readers_Writers;