shared - no read/write access

Stefan Koch uplink.coder at googlemail.com
Mon Mar 25 10:39:06 UTC 2019


On Monday, 25 March 2019 at 08:37:42 UTC, Kagamin wrote:
> On Thursday, 21 March 2019 at 20:50:09 UTC, Manu wrote:
>> But that's now what `shared` does... it allows (guarantees 
>> even) many
>> threads mutate the same data at random with no protections.
>> By inhibiting read/write access, you force the user to obtain 
>> a lock
>> (or other synchronisation method) in order to access the 
>> shared data.
>> Without that, the path of least resistance is to just access 
>> the data,
>> and that's a race 100% of the time, by definition (because it's
>> `shared`).
>
> Some memory accesses are thread safe, then synchronization is 
> not needed.

So what you are saying is that shared can thread-safe;
For access where synchronization is not needed.
In those cases it technically does not matter if the data is 
shared or not.
Let's talk about the case now where data is actually shared 
between threads,
How can I distinguish in the type-system if I get a pointer which 
others may, write to at the same time?

Cheers,
Stefan


More information about the Digitalmars-d mailing list