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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,78546269947cb927 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-29 16:33:34 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!border1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!nntp.giganews.com!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Combining entry_call, accept_statment and terminate_statment From: James Rogers References: Message-ID: User-Agent: Xnews/5.04.25 Date: Tue, 30 Mar 2004 00:33:34 GMT NNTP-Posting-Host: 12.73.180.12 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1080606814 12.73.180.12 (Tue, 30 Mar 2004 00:33:34 GMT) NNTP-Posting-Date: Tue, 30 Mar 2004 00:33:34 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:6662 Date: 2004-03-30T00:33:34+00:00 List-Id: Lutz Donnerhacke 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