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: 103376,4bd6ca8f7a1eb225 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.0.170 with SMTP id 10mr1738089pbf.2.1322619835135; Tue, 29 Nov 2011 18:23:55 -0800 (PST) Path: lh20ni41167pbb.0!nntp.google.com!news1.google.com!postnews.google.com!h42g2000yqd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Class with task destructor Date: Tue, 29 Nov 2011 18:21:51 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <30604696.94.1322013045135.JavaMail.geo-discussion-forums@yqzz20> <24938373.1788.1322615481874.JavaMail.geo-discussion-forums@yqjo5> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1322619835 9136 127.0.0.1 (30 Nov 2011 02:23:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 30 Nov 2011 02:23:55 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h42g2000yqd.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: news1.google.com comp.lang.ada:19250 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-11-29T18:21:51-08:00 List-Id: On Nov 29, 5:11=A0pm, "Rego, P." 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 > > =A0 =A0procedure Destruct (T : access Test_Class) is > =A0 =A0 =A0 T_Ptr : Test_Class_Ptr :=3D Test_Class_Ptr (T); > =A0 =A0begin > =A0 =A0 =A0 T.Primary.Finish; > =A0 =A0 =A0 DelayUntilTaskTermination (T_Ptr.Primary); > =A0 =A0 =A0 Free (T_Ptr); > =A0 =A0end 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