comp.lang.ada
 help / color / mirror / Atom feed
From: Natasha Kerensikova <lithiumcat@instinctive.eu>
Subject: Re: Should weak counted reference be able to be strengthened?
Date: Sat, 22 Nov 2014 10:36:15 +0000 (UTC)
Date: 2014-11-22T10:36:15+00:00	[thread overview]
Message-ID: <slrnm70pp4.nrc.lithiumcat@nat.rebma.instinctive.eu> (raw)
In-Reply-To: 169juip09gkti$.5p7jlls4ehjz.dlg@40tude.net

On 2014-11-22, Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
> On Sat, 22 Nov 2014 09:57:05 +0000 (UTC), Natasha Kerensikova wrote:
>> generic
>>    type Held_Data (<>) is limited priavte;
>> package Natools.References is
>>    [...]
>> private
>>    type Data_Access is access Held_Data;
>
> This won't work. A pool-specific pointer should be the package's parameter,
> since the objects are allocated outside the package, aren't they?

They aren't. I find it much easier to deal with memory in the private
parts of a single package.

References are normally created using:

   function Create
     (Constructor : not null access function return Held_Data)
      return Reference;


(To be perfectly honest, I later added an access based constructor where
the client performs the allocation, but only to prevent an internal copy
from the function return to the allocated memory in a non-limited large
object instance (large enough to have the program OOM-killed when using
an internal copy, while an external build-in-place fits in the target
system memory).
You can inspect the whole code at
https://github.com/faelys/natools/blob/trunk/src/natools-references__protected.ads
)

>> However, what are the serious problems I'm supposed to have?
>> I have used this implementation with task types, but I have yet to
>> encounter any.
>
> The problem is that when you deallocate a task that is not yet terminated.
> A typical code deallocating tasks looks like:
>
>    T.Shut_Down; -- Go away!
>    while not T'Terminated loop -- Still here?
>       delay 0.01;
>    end loop;
>    Free (T); -- We are ready now
>
> This is basically the same issue as with your Reference type which may
> outlive the object. So are some internal things associated with the task,
> which may outlive the object deallocated when the access-to-task is freed.
>
> This is a complicated design with no reason (in case of tasks, there is a
> reason). Why should reference outlive the object?

How could a reference outlive the object?
The object is deallocated only in the Finalize of the last reference.


Natasha


  reply	other threads:[~2014-11-22 10:36 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-21 11:07 Should weak counted reference be able to be strengthened? Natasha Kerensikova
2014-11-21 13:16 ` Dmitry A. Kazakov
2014-11-21 15:00   ` Natasha Kerensikova
2014-11-21 16:50     ` Dmitry A. Kazakov
2014-11-21 18:24       ` Natasha Kerensikova
2014-11-21 19:36         ` Dmitry A. Kazakov
2014-11-21 22:28           ` Randy Brukardt
2014-11-22  9:57           ` Natasha Kerensikova
2014-11-22 10:19             ` Dmitry A. Kazakov
2014-11-22 10:36               ` Natasha Kerensikova [this message]
2014-11-22 11:15                 ` Dmitry A. Kazakov
2014-11-21 22:39       ` Randy Brukardt
2014-11-21 22:49         ` Shark8
2014-11-22  8:42           ` Dmitry A. Kazakov
2014-11-22  8:42         ` Dmitry A. Kazakov
2014-11-24 22:15           ` Randy Brukardt
2014-11-25  8:36             ` Dmitry A. Kazakov
2014-11-25 21:49               ` Randy Brukardt
2014-11-26  9:28                 ` Dmitry A. Kazakov
2014-11-26 17:51                   ` brbarkstrom
2014-11-26 21:09                   ` Randy Brukardt
replies disabled

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