An important pull request: accessing shared affix for immutable data

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 13 08:55:31 PST 2016


On 13.02.2016 03:35, Andrei Alexandrescu wrote:
> On 02/12/2016 09:21 PM, Timon Gehr wrote:
>> Const could also mean mutable. This can hence reference the same data as
>> both shared and unshared, which violates the type system.
>
> If const comes from mutable, then shared is superfluous leading to extra
> synchronization. That's suboptimal, but how does it violate the type
> system? -- Andrei

One point of 'shared' is that data which is _not_ shared cannot be 
mutated by some other thread while you are manipulating it.

'shared' data can be accessed by multiple threads simultaneously.
Unshared data can be accessed by only one thread at a time.
'shared' data can be passed freely among threads.

If you alias the same data as both shared and unshared, the shared 
version can be sent to another thread which will then modify it, 
violating the guarantees on the unshared reference.


More information about the Digitalmars-d mailing list