how to assign to shared obj.systime?

Kagamin spam at here.lot
Sat Jul 11 05:03:55 UTC 2020


On Friday, 10 July 2020 at 17:18:25 UTC, mw wrote:
> On Friday, 10 July 2020 at 08:48:38 UTC, Kagamin wrote:
>> On Friday, 10 July 2020 at 05:12:06 UTC, mw wrote:
>>> looks like we still have to cast:
>>> as of 2020, sigh.
>>
>> Why not?
>
> Because cast is ugly.

Implicitly escaping thread local data into shared context is much 
uglier than a cast. D disallows such implicit sharing, and thus 
ensures existence of thread local data on the language level. 
SysTime wasn't designed to be shared and due to this is 
incompatible with sharing by default, which enforces the promise 
that SysTime must be thread local, because it wasn't designed to 
be shared.

synchronized setTime(ref SysTime t) shared {
     (cast()this).time = t;
}
Steven's solution isn't good in the general case, because it 
still puts thread local data in shared context, which itself is a 
problem, because it makes thread local data implicitly shared, 
and when you work with such implicitly shared thread local data, 
you can't assume it's thread local, because it might be escaped 
into shared context. In this case the language prevented implicit 
sharing of thread local data (this is what shared does and does 
it well contrary to the popular myth that shared is broken).


More information about the Digitalmars-d-learn mailing list