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 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!newspeer1.nac.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Should weak counted reference be able to be strengthened? Date: Sat, 22 Nov 2014 12:15:53 +0100 Organization: cbb software GmbH Message-ID: <19rucjlrdqzqb$.gsp5qs8blu73.dlg@40tude.net> References: <7d9r3whe43z8$.1f2l3n5cz0zh0$.dlg@40tude.net> <1h5a33dishpky.8m2rngmy7e7x$.dlg@40tude.net> <169juip09gkti$.5p7jlls4ehjz.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: wfRpp7ltpEWhI2na6kgpfA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: number.nntp.giganews.com comp.lang.ada:190950 Date: 2014-11-22T12:15:53+01:00 List-Id: On Sat, 22 Nov 2014 10:36:15 +0000 (UTC), Natasha Kerensikova wrote: > On 2014-11-22, Dmitry A. Kazakov 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; You expect all clients having a function (parameterless!) to create objects? This would be barely usable. And this will not work with truly limited types. Constructing functions do not work and never will. A pragmatic design is that the client creates the object by whatever means it finds appropriate and then passes the control over to the first strong reference. Which is quite safe because no explicit pointers involved. For example: declare P : Handle := Ref (new Object (...)); begin OK, in practical cases due to Ada's limitations (lacking constructors and other messes), the code looks rather like: declare P : Handle := Ref (new Derived_Object (...)); This : Derived_Object renames Derived_Object (P.Ptr.all); begin This.Component := ...; -- Doing things Initialize failed to accomplish. >>> 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. Then how a weak reference could access it otherwise? The point is that you need to invalidate weak references at once or else you have keep some object's data no matter where allocated after the object's official death. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de