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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 14 Oct 2014 20:07:44 -0500 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: passing messages between the tasks Date: Tue, 14 Oct 2014 21:07:47 -0400 Organization: IISS Elusive Unicorn Message-ID: <04hr3ap5ivf916e38s5kehq7dsc5hb1q3m@4ax.com> References: <41154c4b-6158-4701-ab25-85afa3b24ed2@googlegroups.com> <9fa74920-0bb1-49d4-93ac-f781529f0c98@googlegroups.com> X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 108.68.178.170 X-Trace: sv3-wBc+a7mSF/3f56bNk8281chAeO2WhYYaLtglgek6rBhQnQRN2xZrsBGR+b7eOrGI+9b8aTcO93bVYYo!stt1ZgYiagexzKXLJdbLCvzjirCChMVVsd4qmeey79iwtkjFM5gGN/OSLQVhQmeqPiNER4GQmqDD!FQlmws/bRAXG9lkR+gAGgATwbNEF X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 5912 Xref: number.nntp.giganews.com comp.lang.ada:189796 Date: 2014-10-14T21:07:47-04:00 List-Id: On Tue, 14 Oct 2014 14:08:08 -0700 (PDT), compguy45@gmail.com declaimed the following: >I am trying to figure out how to do following....have say main tasks call reset on say lamps(3).reset.... >Then lamp(3) would call reset on lamps(2) and lamps(1) and wait....then someone lamps(2) and lamps(1) when they done with reset would somehow let lamp(3) know about it....Is this possible to do...? I do hate given (nearly) full solutions -- but this has gone on a few days too long... So I present... A Working Example (took about 20 minutes to write -- and maybe 10 more to refine the output to where it makes more sense) -=-=-=-=-=- with Ada.Text_IO; use Ada.Text_Io; procedure Taskchain is type Lamp_T; type Lamp_Access_T is access Lamp_T; task type Lamp_T is entry Init (Id : Integer; Left : Lamp_Access_T; Right : Lamp_Access_T); entry Toggle (Level : Integer); entry Shutdown; end Lamp_T; Lamps : array (1 .. 6) of Lamp_Access_T; task body Lamp_T is MyLeft : Lamp_Access_T := null; MyRight : Lamp_Access_T := null; MyId : Integer; State : Boolean := False; begin accept Init (Id : Integer; Left : Lamp_Access_T; Right : Lamp_Access_T) do MyId := Id; MyLeft := Left; MyRight := Right; end Init; Put_Line ("Init Level " & Integer'Image (0) & " Lamp " & Integer'Image (MyId) & " is now " & Boolean'Image (State)); loop select accept Toggle (Level : Integer) do State := not State; Put_Line ("Toggle Level " & Integer'Image (Level) & " Lamp " & Integer'Image (MyId) & " is now " & Boolean'Image (State)); if MyLeft /= null then MyLeft.all.Toggle (Level + 1); end if; if MyRight /= null then MyRight.all.Toggle (Level + 1); end if; end Toggle; or accept Shutdown do Put_Line ("Lamp " & Integer'Image (MyId) & " Shutting Down"); end Shutdown; exit; end select; end loop; end Lamp_T; begin Lamps (6) := new Lamp_T; Lamps (6).Init (Id => 6, Left => null, Right => null); Lamps (5) := new Lamp_T; Lamps (5).Init (Id => 5, Left => null, Right => null); Lamps (4) := new Lamp_T; Lamps (4).Init (Id => 4, Left => Lamps (5), Right => Lamps (6)); Lamps (3) := new Lamp_T; Lamps (3).Init (Id => 3, Left => Lamps (4), Right => null); Lamps (2) := new Lamp_T; Lamps (2).Init (Id => 2, Left => null, Right => null); Lamps (1) := new Lamp_T; Lamps (1).Init (Id => 1, Left => Lamps (2), Right => Lamps (3)); Lamps (6).all.Toggle (0); New_Line; Lamps (4).all.Toggle (0); New_Line; Lamps (2).all.Toggle (0); New_Line; Lamps (1).all.Toggle (0); New_Line; Lamps (1).all.Toggle (0); New_Line; Lamps (3).all.Toggle (0); New_Line; Lamps (1).all.Toggle (0); New_Line; for I in Lamps'Range loop Lamps (I).all.Shutdown; end loop; end Taskchain; -=-=-=-=-=- Init Level 0 Lamp 6 is now FALSE Init Level 0 Lamp 5 is now FALSE Init Level 0 Lamp 4 is now FALSE Init Level 0 Lamp 3 is now FALSE Init Level 0 Lamp 2 is now FALSE Init Level 0 Lamp 1 is now FALSE Toggle Level 0 Lamp 6 is now TRUE Toggle Level 0 Lamp 4 is now TRUE Toggle Level 1 Lamp 5 is now TRUE Toggle Level 1 Lamp 6 is now FALSE Toggle Level 0 Lamp 2 is now TRUE Toggle Level 0 Lamp 1 is now TRUE Toggle Level 1 Lamp 2 is now FALSE Toggle Level 1 Lamp 3 is now TRUE Toggle Level 2 Lamp 4 is now FALSE Toggle Level 3 Lamp 5 is now FALSE Toggle Level 3 Lamp 6 is now TRUE Toggle Level 0 Lamp 1 is now FALSE Toggle Level 1 Lamp 2 is now TRUE Toggle Level 1 Lamp 3 is now FALSE Toggle Level 2 Lamp 4 is now TRUE Toggle Level 3 Lamp 5 is now TRUE Toggle Level 3 Lamp 6 is now FALSE Toggle Level 0 Lamp 3 is now TRUE Toggle Level 1 Lamp 4 is now FALSE Toggle Level 2 Lamp 5 is now FALSE Toggle Level 2 Lamp 6 is now TRUE Toggle Level 0 Lamp 1 is now TRUE Toggle Level 1 Lamp 2 is now FALSE Toggle Level 1 Lamp 3 is now FALSE Toggle Level 2 Lamp 4 is now TRUE Toggle Level 3 Lamp 5 is now TRUE Toggle Level 3 Lamp 6 is now FALSE Lamp 1 Shutting Down Lamp 2 Shutting Down Lamp 3 Shutting Down Lamp 4 Shutting Down Lamp 5 Shutting Down Lamp 6 Shutting Down -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/