comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Problem with task component
Date: Mon, 24 Sep 2012 08:44:32 -0700 (PDT)
Date: 2012-09-24T08:44:32-07:00	[thread overview]
Message-ID: <a1904722-089b-41f5-a4a1-2216a5471e8a@googlegroups.com> (raw)
In-Reply-To: <m2r4pr7rsa.fsf@pushface.org>

On Monday, September 24, 2012 1:23:50 AM UTC-7, Simon Wright wrote:

> What I wanted to do was to be able to write 'terminate' and to have the
> runtime realise that finalization of the object containing the task
> would be a good reason to take the terminate alternative[1].

> 
> [1] See, for example, the last three paras of John English's book ch19
> sec3,
> http://faculty.cs.wwu.edu/reedyc/AdaResources/bookhtml/ch19.htm#19.3
> 
>    This solution requires the master task to call Shutdown explicitly
>    when it wants to terminate the task. The disadvantage with this
>    approach is that it’s possible to forget to call Shutdown. A better
>    solution is to add a terminate alternative to the select statement:

I've been trying to think of a way to get around the "forget" problem by using controlled types.  My first thought was to define a controlled record (i.e. derived from Ada.Finalization.Limited_Controlled) that has a task as a component, and have the Finalize routine for the controlled type call the Shutdown entry.  That way, since the shutdown protocol would be defined, in essence, right by the definition of the task type, there's no way a procedure that uses the type could "forget" to call Shutdown.  No good, though; 7.6.1(4) says that the Finalize routine on the record object would be called *after* the task terminates.  So it would be too late.

A couple thoughts: (1) This isn't the first time I've seen a case where it would be useful for a task to be notified that someone wants to finalize it.  There have been several posts to c.l.a in the past by posters who tried Unchecked_Deallocation on an object containing a task, thinking it would shut down the task, and were surprised by the program's behavior.  I'm not convinced that it's a good idea to redefine "terminate" so that an attempt to finalize an object can cause an open terminate alternative to be selected; but, perhaps, it might be useful for a task to define an entry that is "bound" to a finalization attempt, so that if an object containing a task becomes eligible for finalization (i.e. the master on which it depends is being finalized, or an object that contains it is being deallocated), then that entry is called.  Or maybe there are other approaches.  But it does seem to me that this sort of functionality is one that could be useful but that the language makes it difficult to achieve.

(2) Off the top of my head, I don't see any *implementation* reason why a selective accept couldn't have both a delay alternative and a terminate alternative.  It seems like it wouldn't require the runtime library to do anything it doesn't already know how to do.

                        -- Adam



  parent reply	other threads:[~2012-09-24 15:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-19 18:22 Problem with task component Simon Wright
2012-09-19 18:48 ` Dmitry A. Kazakov
2012-09-19 20:40   ` Simon Wright
2012-09-19 21:11     ` Dmitry A. Kazakov
2012-09-19 21:48       ` Simon Wright
2012-09-24  5:28         ` J-P. Rosen
2012-09-24  8:23           ` Simon Wright
2012-09-24 13:37             ` J-P. Rosen
2012-09-24 14:17               ` Simon Wright
2012-09-24 17:53               ` Robert A Duff
2012-09-24 20:40                 ` J-P. Rosen
2012-09-24 15:44             ` Adam Beneschan [this message]
2012-09-24 16:13               ` AdaMagica
2012-09-24 16:43                 ` Adam Beneschan
2012-09-24 16:29               ` Dmitry A. Kazakov
2012-09-24 20:49                 ` J-P. Rosen
2012-09-25  7:35                   ` Dmitry A. Kazakov
2012-09-25 17:52                     ` J-P. Rosen
2012-09-25 18:35                       ` Dmitry A. Kazakov
2012-09-25 19:22                         ` J-P. Rosen
2012-09-26  7:27                           ` Dmitry A. Kazakov
2012-09-26 11:49                             ` Georg Bauhaus
2012-09-26 14:13                               ` Dmitry A. Kazakov
2012-09-19 19:44 ` Adam Beneschan
replies disabled

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