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=ham 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 Received: by 10.68.39.100 with SMTP id o4mr440378pbk.0.1321550414612; Thu, 17 Nov 2011 09:20:14 -0800 (PST) Path: h5ni2110pba.0!nntp.google.com!news1.google.com!postnews.google.com!g27g2000pre.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Freezing a task Date: Thu, 17 Nov 2011 09:13:53 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <32992849.648.1321544004241.JavaMail.geo-discussion-forums@vbmh5> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1321550412 7372 127.0.0.1 (17 Nov 2011 17:20:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 17 Nov 2011 17:20:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g27g2000pre.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: news1.google.com comp.lang.ada:18954 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-11-17T09:13:53-08:00 List-Id: On Nov 17, 7:33=A0am, "Rego, P." wrote: > Is is possible to freeze a task? > > I mean, if I have a task > > task body My_Task is > begin > =A0 accept Start; > =A0 loop > =A0 =A0 Put ("1"); > =A0 =A0 Put ("2"); > =A0 =A0 Put ("3"); > =A0 =A0 ... > =A0 =A0 Put ("n"); > =A0 end loop; > end My_Task; > > is there a way that I can "freeze" the task in its current state? If, for= instance, the execution finished executing Put ("2");, how can I freeze it= and later I can turn it to continue? I want to provoque a freeze from outs= ide the task, and also from outside, order it to continue. > > I could sure implement, if I had the spec like > > type State_Type is > =A0 (RUN, > =A0 =A0FROZEN); > > task type My_Task (State : State_Type) is > =A0 =A0entry Start; > end My_Task; > -- > > the body: > > task body My_Task is > begin > =A0 accept Start; > =A0 loop > =A0 =A0 Put ("1"); > =A0 =A0 Put ("2"); > =A0 =A0 Put ("3"); > =A0 =A0 ... > =A0 =A0 Put ("n"); > > =A0 =A0 loop > =A0 =A0 =A0if State =3D RUN then exit; end if; > =A0 =A0 end loop; > =A0 end loop; > end My_Task; > > but it would not be the case because I had to wait for the nth Put instru= ction line (i.e., the task would not be actually frozen, because the inside= loop would be running). > > And T.E.D. from stackoverflow suggested me something that I could infer a= s > > task type My_Task (Start : Start_Type) is > =A0 =A0entry Start; > =A0 =A0entry Run; > end My_Task > -- > task body My_Task is > begin > =A0 accept Start; > =A0 loop > =A0 =A0 Put ("1"); > =A0 =A0 Put ("2"); > =A0 =A0 Put ("3"); > =A0 =A0 ... > =A0 =A0 Put ("n"); > > =A0 =A0 if State =3D FROZEN then > =A0 =A0 =A0 =A0accept Run; > =A0 =A0 =A0 =A0State :=3D RUN; > =A0 =A0 end if; > =A0 end loop; > end My_Task; > > Is there a more elegant way to do this? Maybe some procedure My_Task.Free= zeNow in a unknown (by me) package? Thanks Aside from the other suggestions, you might want to look into Ada.Synchronous_Task_Control and Ada.Asynchronous_Task_Control. I'm not really clear on what you're trying to accomplish, so it's hard for me to say whether those are appropriate solutions for you. I think that the other methods that have been suggested--an entry call on another task or on a protected object, or an ACCEPT statement--would be preferable if they get the job done. -- Adam