Yurttas/PL/IL/Ada-95/F/06/p-c/producer consumer 01.adb

From ZCubes Wiki
Jump to navigation Jump to search
 1--
 2-- Copyright(C) 1998
 3-- All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4--
 5-- Permission to use, copy, modify, and distribute this
 6-- software and its documentation for EDUCATIONAL purposes
 7-- and without fee is hereby granted provided that this
 8-- copyright notice appears in all copies.
 9--
10 
11-- date   : January 1, 1998.
12-- author : Salih Yurttas.
13
14-- producer_consumer_01.adb
15
16
17with Ada.Text_IO;
18use Ada.Text_IO;
19
20procedure Producer_Consumer_01 is
21
22  type Unit is new Integer;
23
24  package Int_IO is new Integer_IO(Unit);
25  use Int_IO;
26
27  task Ring_Buffer is
28    entry G(A : out Unit);
29    entry P(A : in Unit);
30  end Ring_Buffer;
31
32  task body Ring_Buffer is
33    Item : Unit;
34  begin
35
36    loop
37      accept P(A : in Unit) do
38        Item := A;
39        Put(Item);
40        New_line;
41      end P;
42
43      accept G(A : out Unit) do
44        A := Item;
45        Put(A);
46        New_line;
47      end G;
48    end loop;
49
50  end Ring_Buffer;
51
52  task Producer;
53
54  task body Producer is
55    Item : Unit;
56  begin
57
58    loop
59      Item := 9;
60      Ring_Buffer.P(Item);
61    end loop;
62
63  end Producer;
64
65  task Consumer;
66
67  task body Consumer is
68    Item : Unit;
69  begin
70
71    loop
72      Ring_Buffer.G(Item);
73    end loop;
74
75  end Consumer;
76
77begin
78
79  null;
80
81end Producer_Consumer_01;