On 7/10/20 2:30 PM, mw wrote:
On Friday, 10 July 2020 at 17:35:56 UTC, Steven Schveighoffer wrote:
Mark your setTime as shared, then cast away shared (as you don't need atomics once it's locked), and assign:

synchronized setTime(ref SysTime t) shared {
    (cast()this).time = t;
}

I know I can make it work by casting, my question is:

we had a lock on the owning shared object already, WHY we still need the cast to make it compile.


Because locking isn't that simple. There is no "one size fits all" locking scheme that can be enforced by the language. So the best option is to make sure if you shoot yourself in the foot, it's your fault, and not D's.

-Steve

Reply via email to