implicit conversions to/from shared

ag0aep6g via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 11 06:54:49 PDT 2016


On 07/11/2016 03:31 PM, Kagamin wrote:
> Atomic loads are only needed for volatile variables, not for all kinds
> of shared data.

Volatile just means that another thread can mess with the data, right? 
So shared data that's not being written to from elsewhere isn't 
volatile, and one doesn't need an atomic load to read it.

If I got that right: Sure. But the compiler can't know if a shared 
variable is volatile or not, so it has to assume that it is. If the 
programmer knows that it's not volatile, they can cast shared away and 
use a normal load.

> Also currently atomicLoad doesn't provide functionality
> equivalent to raw load.

Is a "raw load" just a non-atomic load, or is it something special?
What's the relevance of atomicLoad's capabilities?

>> Generating atomic operations would break less code, and feels like the
>> obvious thing to me.
>
> Multithreaded code can't be generated.

For primitive types, atomic loads and stores can be generated, no? It's 
clear that this doesn't make the code automatically thread-safe. It just 
guards against an easily made mistake. Like shared is supposed to do, as 
far as I understand.


More information about the Digitalmars-d mailing list