From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e1eb00e18fe42be8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-11-01 18:43:44 PST Path: nntp.gmd.de!xlink.net!rz.uni-karlsruhe.de!news.uni-stuttgart.de!news.belwue.de!zib-berlin.de!zrz.TU-Berlin.DE!netmbx.de!Germany.EU.net!EU.net!howland.reston.ans.net!swiss.ans.net!solaris.cc.vt.edu!news.mathworks.com!yeshua.marcam.com!uunet!dziuxsolim.rutgers.edu!pegasus.rutgers.edu!not-for-mail From: yorkie@pegasus.rutgers.edu (Sandra Buyo) Newsgroups: comp.lang.ada Subject: Help on Ada program !! Date: 1 Nov 1994 09:00:00 -0500 Organization: Rutgers University Distribution: usa Message-ID: <395hl0$ai0@pegasus.rutgers.edu> NNTP-Posting-Host: pegasus.rutgers.edu Keywords: Ada program !! Date: 1994-11-01T09:00:00-05:00 List-Id: *****************************************************************8 Hi I need to write this program for someone but I am not familiar with ada so I thouight I could ask around to see what I could find out Basically the code needs to be added in where the ***'s are!! I recognise this to be similiar to pascal but I am not familiar with the syntax of ada !! Can anyone out in cyberspace help !! *********************************************************************** Given a pair of cooperating processes, one "producing" data items(producer) "consumed" by the other(consumer) with possible disparity between production and consumption rates: Devise a synchronization protocol that allows both the producer and the consumer to operate concurrently at their respective service rates in such a way that the produced items are consumed in the exact rate in which they are produced(FIFO). Below is a partial solution to the bounded buffer problem. You must complete the code by adding the code for the "remove" entry of the buffer task and by adding the call to remove within the consumer task. You must also add the initial call to start the buffer process---this call should be placed within the code of the cons_prod procedure. The places where you must add code are marked by ***. with TEXT_IO; use TEXT_IO; procedure cons_prod is item : CHARACTER; task type consumer; task type producer; task type buffer is entry start_buffer; entry insert(item : in CHARACTER); entry remove(item : out CHARACTER); end buffer; c : consumer; p : producer; b : buffer; task body buffer is -- Body of buffer n : constant integer := 100; count : integer range 0..n := 0; in_ch, out_ch : integer range 1..n := 1; bound_buf : array(1..n) of CHARACTER; item : CHARACTER; begin accept start_buffer do put_line("Starting buffer"); end; put_line("Buffer is active"); loop select -- Execute the producer loop or consumer loop when count < n => -- If buffer not full then accept -- an Insert request. -- Add the character to the buffer -- Update the current buffer position -- Update "count" accept insert( item: in CHARACTER ) do bound_buf(in_ch) := item; -- Store item in bound_buf in_ch:= (in_ch mod n) + 1; -- Modulo-increment in_ch count := count + 1; end; or when --*** -- If buffer not empty then accept -- a Remove request. -- Remove the character from the buffer -- Update the current buffer position -- Update "count" or terminate; end select; end loop; put_line("Want to exit buffer"); end buffer; task body consumer is -- Body of consumer item : CHARACTER; begin put_line("Consumer is active"); loop -- Invoke the function to remove item from buffer --*** put(item); -- Display on screen exit when item = 'Z'; -- Stop when item = 'Z' end loop; put_line("Want to exit consumer"); end consumer; task body producer is -- Body of task producer item : CHARACTER; begin put_line("Producer is active"); loop get(item); -- Get from keyboard b.insert(item); exit when item = 'Z'; -- Stop when item = 'Z' end loop; put_line("Want to exit producer"); end producer; begin put("producer/consumer problem"); NEW_LINE; -- Invoke the buffer process --*** end cons_prod;