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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!backlog1.nntp.ams.giganews.com!backlog1.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Natasha Kerensikova Newsgroups: comp.lang.ada Subject: Re: Reference counting and idempotent finalize Date: Mon, 30 Sep 2013 06:25:15 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Mon, 30 Sep 2013 06:25:15 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="31d6bde745a337034b005384ef225743"; logging-data="9397"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uE4zjZ1U4uAvMtlbLm5XF" User-Agent: slrn/0.9.9p1 (FreeBSD) Cancel-Lock: sha1:JgBEkC+97SND8mVxBiAwq4lUgRE= X-Original-Bytes: 2860 Xref: number.nntp.dca.giganews.com comp.lang.ada:183525 Date: 2013-09-30T06:25:15+00:00 List-Id: Hello, On 2013-09-11, Natasha Kerensikova wrote: > I have recently reinvented the reference counted wheel, and been told > that I got it all wrong because Finalize must be idempotent. However I > already diffusely knew that, though I cannot remember from where it > comes or whether I thought of it as a hard requirement or only as a good > practice (the difference is hard to tell when such a rule is > internalized). > > Anyway, my naive implementation looks like that: > > [...] So I have published the implementation on github (and on a public fossil repository on my server, but that's nearly as trendy), it's available at : https://github.com/faelys/natools/blob/trunk/src/natools-references.ads One feature it has that I haven't found it most other implementations mentioned here or found through a web search, is that it places no requirement on the referenced type. In particular, it allows creating reference to any existing type without having to change it, e.g. Ada.Text_IO.File_Type. The fact that it supports referencing to a limited type is a large part of my needs. I remember someone here (I think it was Randy) saying that limited types are a pain and should be avoided in public interfaces, in favor of a reference-semantic non-limited type. So I declare the intrinsically limited type in the private part of the specification and use the reference counter to provide the semantics of the public type. That's why I haven't found the need yet for weak references or concurrency. Any comment about my code is welcome, should anyone take the time to have a look at it. Thanks for your help, Natasha