comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Class with task destructor
Date: Tue, 29 Nov 2011 18:21:51 -0800 (PST)
Date: 2011-11-29T18:21:51-08:00	[thread overview]
Message-ID: <c27dbc9a-fa2e-4ecb-a81f-fe5f8915be3d@h42g2000yqd.googlegroups.com> (raw)
In-Reply-To: 24938373.1788.1322615481874.JavaMail.geo-discussion-forums@yqjo5

On Nov 29, 5:11 pm, "Rego, P." <pvr...@gmail.com> wrote:
> > You ought to wait until the task has terminated before freeing it.
>
> How could I wait for the task termination?
> Could be something like
>
>    procedure Destruct (T : access Test_Class) is
>       T_Ptr : Test_Class_Ptr := Test_Class_Ptr (T);
>    begin
>       T.Primary.Finish;
>       DelayUntilTaskTermination (T_Ptr.Primary);
>       Free (T_Ptr);
>    end Destruct;
>
> ? But is there some package with something like it?

Ada.Task_Termination (see C.7.3) may be able to help.  You could
define a protected object with a handler that sets a toggle and an
entry that waits on the toggle, use Set_Specific_Handler to cause the
handler to be executed when the task terminates, then call the
protected entry to wait for the toggle.  (Maybe someone's already
written a publicly available package that defines a
Delay_Until_Task_Termination routine that could be used on
T_Ptr.Primary'Identity, and with underscores in the name so it doesn't
look like a *&#@^#$ Windows API routine...  :)  I haven't tried this,
by the way.

The problem with waiting on the Finish entry of the task, as you
attempted to do in your next post, is that it may create a race
condition.  After the rendezvous is completed, there still may be some
delay between the time the task finishes the ACCEPT and the time it
actually terminates, and that still makes it possible that the caller
could try to free the task before it has actually terminated (which is
a bounded error according to the RM).  I don't know of a good way
around this (besides Ada.Task_Termination).  Maybe there are some
missing features in the language, such as (for instance) a TERMINATE
statement that can be used inside an ACCEPT statement that causes the
task to terminate, completes the rendezvous, and guarantees that when
the calling task is unblocked, the called task will be terminated.

                           -- Adam



  reply	other threads:[~2011-11-30  2:23 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-23  1:50 Class with task destructor Rego, P.
2011-11-23  2:44 ` Adam Beneschan
2011-11-23  5:04   ` Yannick Duchêne (Hibou57)
2011-11-23  6:14     ` Adam Beneschan
2011-11-24  0:15       ` Randy Brukardt
2011-11-24  2:48         ` Adam Beneschan
2011-11-29  3:36           ` Randy Brukardt
2011-11-29  9:31             ` Simon Wright
2011-11-29 15:37             ` Adam Beneschan
2011-11-23  8:35 ` Dmitry A. Kazakov
2011-11-23  9:05   ` Simon Wright
2011-11-23 10:41     ` Dmitry A. Kazakov
2011-11-30  1:11     ` Rego, P.
2011-11-30  2:21       ` Adam Beneschan [this message]
2011-11-30  8:41         ` Dmitry A. Kazakov
2011-12-01  0:35           ` Randy Brukardt
2011-12-01  6:28             ` J-P. Rosen
2011-12-01 10:55               ` Simon Wright
2011-12-01 21:48               ` Robert A Duff
2011-12-01 22:44                 ` Adam Beneschan
2011-12-02  0:57                 ` Randy Brukardt
2011-12-02  5:57                 ` J-P. Rosen
2011-12-02 15:07                   ` Robert A Duff
2011-12-02 18:41                   ` Jeffrey Carter
2011-12-01  9:25             ` Dmitry A. Kazakov
2011-12-01  1:58         ` Rego, P.
2011-11-30  8:35       ` Simon Wright
2011-11-30 15:36         ` Adam Beneschan
2011-11-30 16:32           ` Robert A Duff
2011-12-01  0:40             ` Randy Brukardt
2011-12-01  8:50               ` Yannick Duchêne (Hibou57)
2011-12-02  0:50                 ` Randy Brukardt
2011-12-02  5:30                   ` Jeffrey Carter
2011-12-02 16:20                     ` Adam Beneschan
2011-12-02 18:01                       ` Dmitry A. Kazakov
2011-12-02 18:50                       ` Jeffrey Carter
2011-12-02 19:03                         ` Adam Beneschan
2011-12-01 10:51           ` Simon Wright
2011-12-01 22:59             ` Simon Wright
2011-12-01  1:59         ` Rego, P.
2011-11-30  1:47     ` Rego, P.
     [not found]     ` <15090042.1880.1322617401962.JavaMail.geo-discussion-forums@yqkn8>
2011-11-30  8:43       ` Dmitry A. Kazakov
2011-12-01  1:53         ` Rego, P.
2011-12-01  9:28           ` Dmitry A. Kazakov
2011-11-25  2:44   ` Rego, P.
     [not found]   ` <28489797.1088.1322188495508.JavaMail.geo-discussion-forums@yqf20>
2011-11-25  9:19     ` Dmitry A. Kazakov
2011-11-29  3:40       ` Randy Brukardt
2011-11-23 10:26 ` Brian Drummond
2011-11-25  1:37   ` Rego, P.
2011-11-25 13:40     ` Brian Drummond
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox