On Monday, 1 October 2018 at 02:29:40 UTC, Manu wrote:
struct Bob
{
void setThing() shared;
}
As I understand, `shared` attribution intends to guarantee that
I dun
synchronisation internally.
This method is declared shared, so if I have shared instances,
I can
call it... because it must handle thread-safety internally.
void f(ref shared Bob a, ref Bob b)
{
a.setThing(); // I have a shared object, can call shared
method
b.setThing(); // ERROR
}
Instead of making mutable->shared conversion implicit, you use
template this parameters:
struct B
{
void setThing(this T)()
{
static if(is(T == shared(B)))
{
/* do synchronisation */
}
else
{
/* all other cases */
}
}
}
I think that it's great that mutable(T) is not implicitly
convertible to shared(T) as it makes synchronization bugs a lot
more obvious.
Cheers,
RazvanN