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 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Termination of periodic tasks Date: Mon, 16 Jun 2014 17:08:42 +0200 Organization: cbb software GmbH Message-ID: <13go3b52zfojz$.s0ft11yb9bmx$.dlg@40tude.net> References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: QTaafVZuunHujkJPndFR7g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 3218 Xref: number.nntp.dca.giganews.com comp.lang.ada:186972 Date: 2014-06-16T17:08:42+02:00 List-Id: On Mon, 16 Jun 2014 14:02:47 +0000 (UTC), Natasha Kerensikova wrote: > On 2014-06-15, Jeffrey Carter wrote: >> On 06/15/2014 03:10 AM, Natasha Kerensikova wrote: >>> >>> A timed select to wait for an entry that exists the loop would be fine >>> too, but how can I detect program termination to call the entry? >>> Could something be worked with a user-defined Finalize? >> >> ARM 7.6.1 says, "For the finalization of a master, dependent tasks are first >> awaited, as explained in 9.3. Then each object ... is finalized if the object >> was successfully initialized and still exists." >> >> So the task has to terminate before Finalize is called. > > That seems at odds with the solution proposed by Dmitry, isn't it? > > Considering the following skeleton spec, > > package To_Be_Discussed is > > task type Typed_Task is > entry Terminate; > end Typed_Task; > > type Task_Access is access Typed_Task; > > task Singleton_Task is > entry Terminate; > end Singleton_Task; > > type Watcher is new Ada.Finalization.Limited_Controlled with record > Signal_Target : Task_Access; > end record; > > overriding procedure Finalize (Object : in out Watcher); > > end To_Be_Discussed; > > As far as I can tell, Singleton_Task and task(s) created using an > allocator for Task_Access have the same master. > > I understood Dimtry's solution as calling Terminate entry from > Watcher.Finalize. > > However what you quote seems to indicate that Watcher.Finalize won't be > called until Singleton_Task and any allocated task in a Task_Access are > termninated by themselves. It will be called. The master here is not the instance of Watcher. Watcher would happen to be the master only if Signal_Target were its component of the Typed_Task. Since you are using rather an access to Typed_Task, everything is OK. When using the solution with an entry the difference to signalling an event is that you have to catch Tasking_Error if the task ended prematurely. Another difference is that when you have a pool of tasks, they may share the same exiting event. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de