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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3a7c118fd2cc64f9 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!kanaga.switch.ch!news-zh.switch.ch!switch.ch!news.belwue.de!LF.net!news.enyo.de!not-for-mail From: Florian Weimer Newsgroups: comp.lang.ada Subject: Re: A hole in Ada type safety Date: Sat, 07 May 2011 11:57:07 +0200 Message-ID: <87oc3en898.fsf@mid.deneb.enyo.de> References: <87oc3odtci.fsf@mid.deneb.enyo.de> <87tydfbtp3.fsf@mid.deneb.enyo.de> <87d3k2u36e.fsf@mid.deneb.enyo.de> <877ha2op0n.fsf@mid.deneb.enyo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ruchba.enyo.de 1304762228 11784 172.17.135.6 (7 May 2011 09:57:08 GMT) X-Complaints-To: news@enyo.de Cancel-Lock: sha1:YLscLBd7WqEZFceP22FEwz6aIPg= Xref: g2news2.google.com comp.lang.ada:20156 Date: 2011-05-07T11:57:07+02:00 List-Id: * Dmitry A. Kazakov: > On Sat, 07 May 2011 11:09:44 +0200, Florian Weimer wrote: > >> Run-time complexity for reference counting is less than for full >> garbage collection. Making it a language feature, rather than a >> library-provided functionality, makes it easier for implementations to >> optimize updating the counts. > > Hmm, what about tasking? I gather that a built-in counter must be atomic. > Whether implemented lock-free or using a spin lock, that would be a > considerable overhead. Modern architectures eliminate most of the overhead in the non-shared case. In the M and E states of the MESI protocol, the operation can be performed locally. There are techniques to emulate this in software, but they require safepointing support, which in turn needs extensive run-time facilities. (A safepoint allows you to carry out in a safe way an operation which is clearly unsafe in the presence of multiple tasks.) Hotspot performs a similar optimization, called biased locking. >> As usual, there is a trade-off between flexibility and overhead: if >> the reference counters are kept separate, it is possible to >> implement weak pointers and safe references to sub-components. > > Interesting. Do you have a certain schema in mind, how to this? The shared pointers in C++ and Boost implement this. Andrei Alexandrescu's Modern C++ Design contains a short overview of implementation choices (but does not cover weak pointers). GCC's implementation of std::share_ptr uses separate pointers to objects and their reference counts. The reference counts contain two counters, for strong and weak references. The actual object is dealloated when the strong count reaches zero. The reference counts are deallocated when the strong and weak counts reach zero.