Newbie initial comments on D language - scope

David Wilson dw at botanicus.net
Sat Feb 2 11:01:46 PST 2008


On 2/2/08, Janice Caron <caron800 at googlemail.com> wrote:
> On 2/2/08, Walter Bright <newshound1 at digitalmars.com> wrote:
> > Doing locked reference counts is slow
>
> Surely you don't need to lock the reference count? You can use atomic
> increment and atomic decrement instead. (I implemented a ref-counted
> template in C++ once, and that's what I did. It seemed to work).
>
> Locking the indirect object itself - that's another matter! However,
> one would imagine that multithreaded code which shares objects will
> already have a mutex system in place, because that would have been
> needed even without ref counting.
>

There are still effects on the CPU cache when using atomic
instructions - namely, every CPU in a multi-CPU system must be
instructed to flush any cache line that would be affected by the
operation. As far as I know this is asserted in x86 via the "LOCK"
instruction prefix.


David.



More information about the Digitalmars-d mailing list