Variable modified by different threads.

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Mon Dec 2 21:55:55 UTC 2024


On 03/12/2024 4:18 AM, Salih Dincer wrote:
> On Monday, 2 December 2024 at 08:00:40 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> You don't need both atomics an mutex's, pick one.
> 
> The compiler wants us to use atomicOp; If you want, take it out of the 
> synchronized(mutex) { } block, it doesn't matter:

That is because you used ``shared``.

As a type qualifier/storage class, ``shared`` should be called ``atomic``.

If you use it to indicate anything other than the variable can only be 
accessed/mutated via atomic operations, you are at best lieing to 
yourself about the native memory model.

All memory is owned by the process, until proven otherwise. Which is the 
exact opposite of what ``shared`` implies.



More information about the Digitalmars-d-learn mailing list