comp.lang.ada
 help / color / mirror / Atom feed
* Help on Ada program !!
@ 1994-11-01 14:00 Sandra Buyo
  1994-11-01 14:40 ` Robert Firth
  1994-11-01 18:43 ` Bob Kitzberger
  0 siblings, 2 replies; 4+ messages in thread
From: Sandra Buyo @ 1994-11-01 14:00 UTC (permalink / raw)



*****************************************************************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;



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help on Ada program !!
  1994-11-01 14:00 Help on Ada program !! Sandra Buyo
@ 1994-11-01 14:40 ` Robert Firth
  1994-11-01 18:43 ` Bob Kitzberger
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Firth @ 1994-11-01 14:40 UTC (permalink / raw)


In article <395hl0$ai0@pegasus.rutgers.edu> yorkie@pegasus.rutgers.edu (Sandra Buyo) writes:

>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 !!

>    task type buffer is

I think most of the answer can be found in the Ada Rationale,
Section 13.2.5, p 280.  It gives the complete body of the
BUFFER task, and seems to be the source from which your
example has been plag^H^H^H^H adopted.

Also, the version you gave contains a couple of errors and
infelicities, that are not present in the original version.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help on Ada program !!
  1994-11-01 14:00 Help on Ada program !! Sandra Buyo
  1994-11-01 14:40 ` Robert Firth
@ 1994-11-01 18:43 ` Bob Kitzberger
  1994-11-01 19:03   ` Sandra Buyo
  1 sibling, 1 reply; 4+ messages in thread
From: Bob Kitzberger @ 1994-11-01 18:43 UTC (permalink / raw)


Sandra Buyo (yorkie@pegasus.rutgers.edu) wrote:

: *****************************************************************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

Looks like a homework assignment, walks like a homework assignment,
quacks like a homework aggignment...


	.Bob.


--
Bob Kitzberger	        +1 (916) 274-3075	        rlk@rational.com
Rational Software Corp., 10565 Brunswick Rd. #11, Grass Valley, CA 95945



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help on Ada program !!
  1994-11-01 18:43 ` Bob Kitzberger
@ 1994-11-01 19:03   ` Sandra Buyo
  0 siblings, 0 replies; 4+ messages in thread
From: Sandra Buyo @ 1994-11-01 19:03 UTC (permalink / raw)


rlk@rational.com (Bob Kitzberger) writes:

>Looks like a homework assignment, walks like a homework assignment,
>quacks like a homework aggignment...


>	.Bob.


Probably is too.  But i am not too sure,.. 

>--
>Bob Kitzberger	        +1 (916) 274-3075	        rlk@rational.com
>Rational Software Corp., 10565 Brunswick Rd. #11, Grass Valley, CA 95945



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1994-11-01 19:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-11-01 14:00 Help on Ada program !! Sandra Buyo
1994-11-01 14:40 ` Robert Firth
1994-11-01 18:43 ` Bob Kitzberger
1994-11-01 19:03   ` Sandra Buyo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox