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,19ad05fdbf4e671f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Deallocating records with task type fields. References: <1134168554.826805.70690@g49g2000cwa.googlegroups.com> In-Reply-To: <1134168554.826805.70690@g49g2000cwa.googlegroups.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sat, 10 Dec 2005 07:16:41 GMT NNTP-Posting-Host: 67.3.219.37 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1134199001 67.3.219.37 (Fri, 09 Dec 2005 23:16:41 PST) NNTP-Posting-Date: Fri, 09 Dec 2005 23:16:41 PST Xref: g2news1.google.com comp.lang.ada:6808 Date: 2005-12-10T07:16:41+00:00 List-Id: Gene wrote: > Please consider these declarations for a task with some task local > data: > > type Listener_Type; > > task type Listener_Task_Type(Env : access Listener_Type); > > type Listener_Type is > record > Port : Positive; > Executive : Listener_Task_Type(Listener_Type'Access); > end record; > > With this, the executive task has access to the task local environment > exemplified here by a port number. > > Here are the questions: > > 1. Is this a good idiom for implementing task local data, or is there > some other preferable method? For a case like this, I'd probably suggest task type Listener (Port : Positive); More generally, how do you create an object of Listener_Type and ensure that you assign a value to its Port component before its Executive accesses that component? An alternative is to not embed the task in its data: task type T (Environment : access Environment_Data); This requires that you have the data available when you create the task object. > 2. As I read the ALRM it is incorrect to deallocate a Listener_Type > object until the Executive task has exited. What is a good idiomatic > way for the Executive to deallocate its own task local storage just > before it exits and without causing a race condition? [The only ways I > can come up with seem like excessive machinery.] The best way is not to use allocation, and thus not need deallocation. If you do need to allocate the data, you can use the access type for that instead of an anonymous access type: task type T (Environment : Data_Ptr); and the task could make a copy of Environment and deallocate that. I would not generally advise such an approach. -- Jeff Carter "I like it when the support group complains that they have insufficient data on mean time to repair bugs in Ada software." Robert I. Eachus 91