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=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7897733b1978b6a4 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.15.41 with SMTP id u9mr3636811pbc.3.1321601077701; Thu, 17 Nov 2011 23:24:37 -0800 (PST) MIME-Version: 1.0 Path: h5ni4545pba.0!nntp.google.com!news1.google.com!goblin3!goblin1!goblin.stu.neva.ru!news.ett.com.ua!not-for-mail From: anon@att.net Newsgroups: comp.lang.ada Subject: Re: Freezing a task Date: Fri, 18 Nov 2011 07:24:35 +0000 (UTC) Organization: ETT newsserver Message-ID: References: <32992849.648.1321544004241.JavaMail.geo-discussion-forums@vbmh5> Reply-To: anon@anon.org NNTP-Posting-Host: dialup-4.225.175.181.dial1.dallas1.level3.net X-Complaints-To: usenet@news.ett.com.ua X-Notice: Filtered by postfilter v. 0.6.1 X-Newsreader: IBM NewsReader/2 2.0 Xref: news1.google.com comp.lang.ada:18964 Date: 2011-11-18T07:24:35+00:00 List-Id: -- -- Complete Program -- with Text_IO ; procedure u is use Text_IO ; task type test is entry Start ; -- initialize and start task -- and task can die if parent stops entry Wait ; -- Send task to sleep for a while -- and task can die if parent stops entry Continue ; -- wake up task entry Stop ; -- stops and kill task end test ; task body test is Count : Integer ; begin -- Initialize task Count := 0 ; Outer_Loop : loop select -- start task accept Start ; Put_Line ( "Start" ) ; Main_Loop : loop select -- pause task accept Wait ; Put_Line ( "Wait" ) ; New_Line ; select -- sofware wake up task accept Continue ; Put_Line ( "Continue" ) ; -- software exit while in wait mode or accept Stop ; Put_Line ( "Stop" ) ; exit Outer_Loop ; -- exit if parent fails while in wait mode or terminate ; end select ; -- software exit (abort) while in normal -- execution mode or accept Stop ; Put_Line ( "Stop" ) ; exit Outer_Loop ; else -- - - - - - - - - - - -- -- Main Tasking Code -- -- - - - - - - - - - - -- Put ( "Testing" ) ; Put ( Integer'Image ( Count ) ) ; New_Line ; Count := Count + 1 ; end select ; end loop Main_Loop ; -- exit if parent fails or terminate ; end select ; end loop Outer_Loop ; Put_Line ( "Task has Terminated" ) ; end test ; testing_task : test ; begin Put_Line ( "Start Tasking" ) ; New_Line ; -- testing_task.Start ; delay ( 0.01 ) ; testing_task.Wait ; delay ( 1.0 ) ; testing_task.Continue ; delay ( 0.01 ) ; testing_task.Wait ; -- delay ( 1.0 ) ; testing_task.Stop ; delay ( 0.5 ) ; New_Line ; end u ; In <32992849.648.1321544004241.JavaMail.geo-discussion-forums@vbmh5>, "Rego, P." writes: >Is is possible to freeze a task? > >I mean, if I have a task > >task body My_Task is >begin=20 > accept Start; > loop > Put ("1"); > Put ("2"); > Put ("3"); > ... > Put ("n"); > end loop; >end My_Task; > >is there a way that I can "freeze" the task in its current state? If, for i= >nstance, the execution finished executing Put ("2");, how can I freeze it a= >nd later I can turn it to continue? I want to provoque a freeze from outsid= >e the task, and also from outside, order it to continue. > >I could sure implement, if I had the spec like > >type State_Type is > (RUN, > FROZEN); > >task type My_Task (State : State_Type) is > entry Start; >end My_Task; >-- > >the body: > >task body My_Task is >begin=20 > accept Start; > loop > Put ("1"); > Put ("2"); > Put ("3"); > ... > Put ("n"); > > loop=20 > if State =3D RUN then exit; end if; > end loop; > end loop; >end My_Task; > >but it would not be the case because I had to wait for the nth Put instruct= >ion line (i.e., the task would not be actually frozen, because the inside l= >oop would be running). > >And T.E.D. from stackoverflow suggested me something that I could infer as > >task type My_Task (Start : Start_Type) is=20 > entry Start; > entry Run; >end My_Task >-- >task body My_Task is >begin=20 > accept Start; > loop > Put ("1"); > Put ("2"); > Put ("3"); > ... > Put ("n"); > > if State =3D FROZEN then=20 > accept Run; > State :=3D RUN; > end if; > end loop; >end My_Task; > >Is there a more elegant way to do this? Maybe some procedure My_Task.Freeze= >Now in a unknown (by me) package? Thanks