[phobos] Atomic Ref Counting

David Simcha dsimcha at gmail.com
Fri Nov 19 11:13:57 PST 2010


Should I make RefCounted and data structures that use it configurable, such
that they're not atomic by default, but can be trivially made atomic?  The
use of non-atomic ref counting makes it impossible to store ref counted data
structures in classes for now, and makes it impossible to share them across
threads forever, even if you synchronize manually.  In cases where they are
not being passed around much, I don't think atomic reference counting is
unreasonably expensive.  I personally would love a version of
std.container.Array with a few issues I've mentioned previously fixed and
with atomic ref counting.

If people like the idea of making this configurable, any input on how?  I
see three ways:

1.  Make RefCounted into a class instead of a struct, and use virtual
functions and interfaces.  (Probably a bad idea, but I'll throw it out there
anyhow).

2.  Store a bool in it and use an if statement.  (I like this.  It allows
runtime flexibility and the perf. cost should be negligible because the
branch will be so predictable.)

3.  Use a template parameter and handle it at compile time.  (I don't like
the idea of atomic and non-atomic ref counted versions of the same container
being different types.  OTOH, this is the most efficient at runtime.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20101119/1909c4a0/attachment.html>


More information about the phobos mailing list