Visual C ++ volatile

The MSDN docs for “volatile” in Visual C ++ indicate that records have “release semantics” and that reading has “acquire semantics”, in addition to the fact that reads are always read from memory and that records are always written accordingly.

The C specification for "volatile" includes the second part (don't do crazy optimizations), but not the first part (memory pickup).

Is there any way in Visual C ++ to get only mutable "C" behavior, without taking memory?

I want the variable to always be on the stack in a fixed place, but I don’t want to take the overhead of taking the memory at each assignment to it.

Is there an easy way to do this using a Visual C ++ source?

+8
c ++ volatile visual-c ++
source share
1 answer

Is there any way in Visual C ++ to get only mutable "C" behavior, without taking memory?

On x86, there are no memory records on the memory records that are read and written to the volatile memory cell, since on this platform each download acquires semantics and each store has release semantics. Therefore, for MSVC on x86, the volatile directive simply directs the compiler to prevent reordering of loads and storages depending on whether you are writing to or reading from the memory location that volatile was marked with.

You will only incur a “penalty” for fencing memory in the IA64 architecture, since the platform’s memory sequencing model does not guarantee receipt and release of semantics for downloads and storages.

Remember that this behavior is specific to MSVC and is not a standardized volatile semantics.

Update . According to @ildjarn, you'll also see memory pickup on ARM with Windows 8, as this platform also has a loosely ordered memory matching model like IA64.

+4
source share

All Articles