Precise GC state

Petar Petar
Mon Nov 27 06:59:30 UTC 2017


On Monday, 27 November 2017 at 06:36:27 UTC, Ola Fosheim Grostad 
wrote:
> On Monday, 27 November 2017 at 05:47:49 UTC, Dmitry Olshansky 
> wrote:
>> likely via RAII. Not to mention cheap (thread-local) Ref 
>> Counting, C++ and many other language have to use atomics 
>> which makes RC costly.
>
> No, you dont. Nobody in their right mind would do so in C++ as 
> a general solution. Seems there is trend in doing D-advocacy 
> based on the assumption that programmers using other languages 
> are crazy these days.
>
> In C++ sync is manual, which is the only efficient way to do 
> it. Proving correctness for an efficient general solution is an 
> unsolved theoretical problem. You can do it for high level 
> mechanisms, but not low level atm.
>
> Rust and Pony claims to have solutions, but they are not 
> general. D most certainly does not have it and never will.
>
> When threading is a libray type then you cannot achieve more in 
> D than you can achieve in C++, i.e. Shared is not going to do 
> more than a C++ library type with a separate static analysis 
> tool.

What I think Dmitry meant is that shared_ptr<T> uses atomic 
instructions for the reference counting (though you need to use 
atomic_shared_ptr, or atomic_* function if you want to modify the 
shared_ptr itself) and you can't opt out of that even if you're 
not sharing the shared_ptr with other threads. On the other hand 
in D, a properly designed SharedPtr(T) will use atomic 
instructions for reference counting, only if it's payload type T 
is has the 'shared' type qualifier. And if you have 
'shared(SharedPtr(T))', only then you'll have atomic instructions 
for the SharedPtr struct itself, but unlike shared_ptr<T>, you 
won't have access to the non-thread safe methods.


More information about the Digitalmars-d mailing list