Escaping the Tyranny of the GC: std.rcstring, first blood

Rainer Schuetze via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 15 22:22:12 PDT 2014



On 15.09.2014 21:49, Andrei Alexandrescu wrote:
> On 9/15/14, 12:43 PM, po wrote:
>>
>>> As I understand the issue it works if you make sure to transfer
>>> ownership explicitly before the other thread gains access?
>>>
>>> Maybe this is more clear:
>>>
>>> http://www.1024cores.net/home/lock-free-algorithms/object-life-time-management/differential-reference-counting
>>>
>>>
>>
>>   Ah, I think I follow.
>>
>> So in C++ terms:
>>   It basically requires either a global shared_ptr, or that you passed
>> one around by reference between threads. And that you then killed it in
>> one thread at the exact moment the control block was read in another
>> thread. That blog post discusses a solution, I wonder if that is
>> implemented in C++'s shared_ptr?
>
> No, and it neeedn't. The article is not that good. In C++, if a thread
> must increment a reference counter while it's going to zero due to
> another thread, that's 100% a programming error, not a concurrency
> error. That's a well known and well studied problem. As an aside,
> searching the net for differential reference counting yields pretty much
> only this article.

Huuh? So you must not read a reference to a ref-counted object that 
might get changed in another thread? Maybe you mean destruction of the 
shared pointer?

Please note that the scenario is also described by Richard Jones in his 
2nd edition of the "Handbook of Garbage Collection" (see algorithm 18.2 
"Eager reference counting with CompareAndSwap is broken").



More information about the Digitalmars-d mailing list