From: James Rogers <jimmaureenrogers@att.net>
Subject: Re: Combining entry_call, accept_statment and terminate_statment
Date: Tue, 30 Mar 2004 00:33:34 GMT
Date: 2004-03-30T00:33:34+00:00 [thread overview]
Message-ID: <Xns94BBB25585C7Cjimmaureenrogers@204.127.36.1> (raw)
In-Reply-To: slrnc6guve.g7p.lutz@belenus.iks-jena.de
Lutz Donnerhacke <lutz@iks-jena.de> wrote in
news:slrnc6guve.g7p.lutz@belenus.iks-jena.de:
> Sorry, but I do not get it:
>
> I have a protected type with an entry:
>
> protected type PT is
> entry X;
> end PT;
> p : PT;
>
> Now I have to construct a task dealing with new data from the
> protected type, an call from other tasks or the termination of the
> parent task.
I ran into this problem when illustrating a producer/consumer
example that emulates a just in time production line. I wanted the
producing tasks to be able to write to a protected object at a
specified rate, but also be able to be shut down through a
rendezvous.
Following is my solution:
--------------------------------------------------------------------------
-- Production Lines
--------------------------------------------------------------------------
with Con_Bon_Pads;
package Production_Lines is
package Tuner_Bufs renames Con_Bon_Pads.Tuner_Buffers;
package Ps_Bufs renames Con_Bon_pads.Ps_Buffers;
task type Tuners is
entry Start(Destination : in Tuner_Bufs.Parts_Buf_Ptr);
entry Stop;
end Tuners;
task type Power_Supplies is
entry Start(Destination : in Ps_Bufs.Parts_Buf_Ptr);
entry Stop;
end Power_Supplies;
task type Radios is
entry Start(Tuner_Src : in Tuner_Bufs.Parts_Buf_Ptr;
PS_Src : in Ps_Bufs.Parts_Buf_Ptr);
entry Stop;
end Radios;
end Production_Lines;
with Assemblies; use Assemblies;
with Ada.Text_Io;
package body Production_Lines is
--------------------
-- Power_Supplies --
--------------------
task body Power_Supplies is
Con_Bon : Ps_Bufs.Parts_Buf_Ptr;
Unit : Assemblies.Power_Supply;
Blocked : Boolean := False;
begin
accept Start(Destination : in Ps_Bufs.Parts_Buf_Ptr)
do
Con_Bon := Destination;
end Start;
Build:
loop
select
accept Stop;
Ada.Text_Io.Put_Line("Power Supply Production Stopped.");
exit Build;
else
delay 1.0;
if not Blocked then
Set_Serial_Number(Unit);
end if;
select
Con_Bon.Put(Unit);
Blocked := False;
or
delay 0.2;
Blocked := True;
end select;
if not Blocked then
Print(Unit);
end if;
end select;
end loop Build;
end Power_Supplies;
------------
-- Radios --
------------
task body Radios is
Power_Supply_Unit : Assemblies.Power_Supply;
Tuner_Unit : Assemblies.Tuner;
Unit : Assemblies.Radio;
Ps_Buf : Ps_Bufs.Parts_Buf_Ptr;
Tuner_Buf : Tuner_Bufs.Parts_Buf_Ptr;
Got_T, Got_P : Boolean := False;
begin
accept Start(Tuner_Src : in Tuner_Bufs.Parts_Buf_Ptr;
Ps_Src : in Ps_Bufs.Parts_Buf_Ptr) do
Ps_Buf := Ps_Src;
Tuner_Buf := Tuner_Src;
end Start;
Build:
loop
select
accept Stop;
Ada.Text_Io.Put_Line("Radio Production Stopped.");
exit Build;
else
if not Got_p then
select
Ps_Buf.Get(Power_Supply_Unit);
Got_P := True;
or
delay 1.5;
end select;
end if;
if not Got_T then
select
Tuner_Buf.Get(Tuner_Unit);
got_T := True;
or
delay 1.5;
end select;
end if;
end select;
if Got_t and Got_P then
delay 1.25;
Unit := Radio_Constructor.Assemble_Radio(Tuner_Unit,
Power_Supply_Unit);
Set_Serial_Number(Unit);
Print(Unit);
Got_T := False;
Got_P := False;
end if;
end loop Build;
end Radios;
------------
-- Tuners --
------------
task body Tuners is
Con_Bon : Tuner_Bufs.Parts_Buf_Ptr;
Unit : Assemblies.Tuner;
Blocked : Boolean := False;
begin
accept Start(Destination : in Tuner_Bufs.Parts_Buf_Ptr)
do
Con_Bon := Destination;
end Start;
Build:
loop
select
accept Stop;
Ada.Text_Io.Put_Line("Tuner Production Stopped.");
exit Build;
else
delay 1.5;
if not Blocked then
Set_Serial_Number(Unit);
end if;
select
Con_Bon.Put(Unit);
Blocked := False;
or
delay 0.2;
Blocked := True;
end select;
if not Blocked then
Print(Unit);
end if;
end select;
end loop Build;
end Tuners;
end Production_Lines;
Jim Rogers
prev parent reply other threads:[~2004-03-30 0:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-29 19:41 Combining entry_call, accept_statment and terminate_statment Lutz Donnerhacke
2004-03-29 22:04 ` Randy Brukardt
2004-03-29 23:19 ` Mark Lorenzen
2004-03-29 23:14 ` Robert I. Eachus
2004-03-30 7:26 ` Lutz Donnerhacke
2004-03-30 20:04 ` Randy Brukardt
2004-03-30 22:47 ` Lutz Donnerhacke
2004-03-31 9:03 ` Dmitry A. Kazakov
2004-03-31 9:14 ` Lutz Donnerhacke
2004-03-31 12:22 ` Dmitry A. Kazakov
2004-03-31 6:39 ` Jean-Pierre Rosen
2004-03-30 7:29 ` Lutz Donnerhacke
2004-03-30 8:11 ` tmoran
2004-03-30 11:45 ` Lutz Donnerhacke
2004-03-30 0:33 ` James Rogers [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox