On Monday, 15 September 2014 at 16:22:01 UTC, Andrei Alexandrescu
wrote:
On 9/15/14, 8:58 AM, Rainer Schuetze wrote:

* immutable means implicitely shared between threads, so you'll have to make RCString thread-safe even if shared isn't explicitly supported.

Hmmm, good point. That's a bug. Immutable postblit and dtors should use atomic ops.

Unfortunately, I've yet to see an efficient thread-safe implementation of reference counting (i.e. without locks).

No locks needed, just interlocked ++/--.

To be fair, you still have to be a bit careful here or things
could be optimized such that data is seen to disappear or change
when it's not expected to.  The original boost::shared_ptr used
an atomic integer as an internal refcount, and that's probably a
good template for how to do RC here.  The newer implementation is
a lot fancier with spinlocks and such, I believe, and is a lot
more complicated.

Also... this is why I'm not over-fond of having immutable being
implicitly shared.  Being unable to create an efficient RCString
that I know is thread-local (the normal case) kind of stinks. Maybe there can be a
template parameter option along these lines?

Reply via email to