comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Freeing access-to-task objects
Date: Sat, 1 Oct 2022 13:58:37 +0200	[thread overview]
Message-ID: <th9a1c$8rn$1@gioia.aioe.org> (raw)
In-Reply-To: th98ui$1atuq$1@dont-email.me

On 2022-10-01 13:40, J-P. Rosen wrote:
> Le 30/09/2022 à 12:16, Emmanuel Briot a écrit :
>> Please find a new blog post at:
>>
>> https://deepbluecap.com/freeing-task-access-objects/
>>
>> Abstract:
>> Freeing Ada tasks could result in accessing freed memory. This post 
>> describes the proper way of freeing access-to-task objects.
> 
> I don't like an active loop to wait for task termination.

IMO, it is the best method.

> There are 
> other ways:
> 1) declare the access type in a block, which is then the master of the 
> tasks. When you exit the block, the tasks are terminated.

That is usually not possible, or if possible, then the task object 
itself can be in the block and no access type needed at all.

Almost all cases when access to task is used is due to language design 
flaw not allowing either usable aggregation of task objects or 
inheritance involving tasks.

> 2) declare in the tasks an entry which is never accepted, then call this 
> entry from the main. When the task terminates, it raises tasking_error 
> in the (unserved) callers - you can free the task from the exception 
> handler.

This is uglier than a loop. However I must admit that it should have 
advantage in terms of performance, both CPU load and latency. A 
disadvantage is that you cannot wait for several tasks that way.

In a production code there is a timeout which limits the overall waiting 
time and sometimes multiple tasks are awaited to terminate.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2022-10-01 11:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 10:16 Freeing access-to-task objects Emmanuel Briot
2022-10-01 11:40 ` J-P. Rosen
2022-10-01 11:58   ` Dmitry A. Kazakov [this message]
2022-10-01 21:26     ` Björn Lundin
2022-10-01 14:01   ` Jeffrey R.Carter
2022-10-01 14:45     ` Emmanuel Briot
2022-10-09 16:10     ` Stephen Leake
2022-10-09 19:42       ` Jeffrey R.Carter
2022-10-10  8:13         ` Simon Wright
2022-10-10 16:35           ` Jeffrey R.Carter
2022-10-10 20:23       ` AdaMagica
replies disabled

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