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, 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.35.68 with SMTP id f4mr1288502pbj.5.1321606067155; Fri, 18 Nov 2011 00:47:47 -0800 (PST) Path: h5ni4786pba.0!nntp.google.com!news1.google.com!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Freezing a task Date: Fri, 18 Nov 2011 09:47:58 +0100 Organization: cbb software GmbH Message-ID: <1ffqisv4jbhfl$.qceqrbo8tnl2$.dlg@40tude.net> References: <32992849.648.1321544004241.JavaMail.geo-discussion-forums@vbmh5> <32201299.75.1321579435782.JavaMail.geo-discussion-forums@yqbl36> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news1.google.com comp.lang.ada:18965 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2011-11-18T09:47:58+01:00 List-Id: On Thu, 17 Nov 2011 17:23:55 -0800 (PST), Rego, P. wrote: >> Paused : Boolean := False; >> begin >> loop >> if Paused then >> accept Release; >> Paused := False; >> else >> select >> accept Pause; >> Paused := True; >> else >> ... -- Do stuff >> end select; >> end if; >> end loop; > > So I can use > > Paused : Boolean := False; > begin > accept Start; > loop > if Paused then > accept Release; > Paused := False; > else > select > accept Pause; > Paused := True; > else > ... -- Do stuff > end select; > end if; > end loop; > > and if I would want to add an abort entry? What should I do? Note that the above has a deadlock when you call to Pause or Release twice. It is easy to correct, but a protected object solution would be more robust. See the Jeffrey's response, however, I would use an exception rather than output parameter: Pending_Abort : exception; protected type Control is procedure Process; procedure Pause; procedure Stop; entry Get; private Paused : Boolean := False; Exiting : Boolean := False; end Control; protected body Control is procedure Process is begin Paused := False; end Process; procedure Pause is begin Paused := True; end Pause; procedure Stop is Exiting := True; end Stop; entry Get when not Paused or Exiting is begin if Exiting then raise Pending_Abort; end if; end Get; private Paused : Boolean := False; Exiting : Boolean := False; end Control; task body T is begin loop Control_Instance.Get; ... -- Do stuff Control_Instance.Get; ... -- Do other stuff Control_Instance.Get; ... -- Do yet another stuff end loop; exception when Pending_Abort => null; end T; You don't need Start entry of the task. Just make Paused initially true. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de