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: a07f3367d7,c33f8f65997c21d0 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,CP1252 Received: by 10.224.213.1 with SMTP id gu1mr10467724qab.7.1348501472727; Mon, 24 Sep 2012 08:44:32 -0700 (PDT) Received: by 10.236.180.41 with SMTP id i29mr1641469yhm.4.1348501472693; Mon, 24 Sep 2012 08:44:32 -0700 (PDT) Path: e10ni13434282qan.0!nntp.google.com!l8no8376807qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 24 Sep 2012 08:44:32 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: <1667b8e2qt7ei$.1gg1h3hrp9amz$.dlg@40tude.net> <187uk10m6z8xj.yr1cpbgrdur$.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Problem with task component From: Adam Beneschan Injection-Date: Mon, 24 Sep 2012 15:44:32 +0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Date: 2012-09-24T08:44:32-07:00 List-Id: 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]. >=20 > [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 >=20 > 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=92s 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 us= ing 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 proced= ure 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 sh= ut down the task, and were surprised by the program's behavior. I'm not co= nvinced 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 "bo= und" to a finalization attempt, so that if an object containing a task beco= mes 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 th= e language makes it difficult to achieve. (2) Off the top of my head, I don't see any *implementation* reason why a s= elective accept couldn't have both a delay alternative and a terminate alte= rnative. It seems like it wouldn't require the runtime library to do anyth= ing it doesn't already know how to do. -- Adam