On Wednesday, 12 April 2017 at 13:32:36 UTC, Stanislav Blinov
wrote:
Syntax is not the core of the issue, it's not about just
marking a destructor as shared. Making RefCounted itself shared
would require implementing some form of synchronization of all
the 'dereference' operations, including assignments. I.e. if we
have some shared(RefCounted!T) ptr, what should happen when two
threads simultaneously attempt to do ptr =
shared(RefCounted!T)(someNewValue) ? Should a library
implementation even consider this? Or should such
synchronization be left to client's care? It seems like in this
regard shared(RefCounted!T) would be no different from
shared(T*), which brings me to the next point.
If we can control memory layout, we can do what shared_ptr does
and couple the reference counter with the object, then we can
have just one pointer:
struct RefCounted(T)
{
struct Wrapper
{
int count;
T payload;
}
Wrapper* payload;
}