On 10/17/18 9:58 AM, Nicholas Wilson wrote:
On Wednesday, 17 October 2018 at 13:25:28 UTC, Steven Schveighoffer wrote:
It's identical to the top one. You now have a new unshared reference
to shared data. This is done WITHOUT any agreed-upon synchronization.
It isn't, you typo'd it (I originally missed it too).
int *p3 = cast(int*)p2;
vs
int *p3 = p;
It wasn't a typo.
It's identical in that both result in a thread-local pointer equivalent
to p. Effectively, you can "cast" away shared without having to write a
cast.
I was trying to demonstrate the ineffectiveness of preventing implicit
casting from shared to mutable if you allow unshared data to implicitly
cast to shared.
It's the same problem with mutable and immutable. It's why we can't
allow the implicit casting. Explicit casting is OK as long as you don't
later modify the data.
In the same vein, explicit casting of local to shared is OK as long as
you don't ever treat the data as local again. Which should requires a
cast to say "I know what I'm doing, compiler".
-Steve