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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Deallocating records with task type fields. Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1134168554.826805.70690@g49g2000cwa.googlegroups.com> Date: Sat, 10 Dec 2005 15:10:50 +0100 Message-ID: <1vb61utj75dws.gjbmfyig7vzz.dlg@40tude.net> NNTP-Posting-Date: 10 Dec 2005 15:10:33 MET NNTP-Posting-Host: 5b6e1b59.newsread2.arcor-online.net X-Trace: DXC=Sg^^anN9OaG5VQnf?UOZgEQ5U85hF6f;DjW\KbG]kaMHn6A=Y6OiEaDVQ7C;m5?]RMWRXZ37ga[7JjTA67ckJ=XElC?>kX^f=KD X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:6814 Date: 2005-12-10T15:10:33+01:00 List-Id: On 9 Dec 2005 14:49:14 -0800, 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? > > 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.] Not really. If data are local then it is task's responsibility to maintain them. Your design inverses this: the life span of environment must enclose one of the task. I presume that you are trying to bring parameters of a task and the local data under one roof. It can work in only simple cases. Possible alternatives: 1. Local things are on the task's stack. Parameters are passed through discriminants. 2. Same as above, but parameters are passed via Start entry point 3. Task is encapsulated into a controlled object which has the parameters and data. A pragmatic way to do this is to have a task pointer as a component, so that task might be allocated separately from the object. Otherwise, there will be problems with initialization and finalization. 4. Smart pointers with reference counting. If you want to create a resource (like local data) for a task in one place and collect it in another (upon task exit) then smart pointers is a safe way to do it. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de