_ReadBarrier
Microsoft Specific
Forces memory reads to complete.
void _ReadBarrier(void);
Requirements
Intrinsic | Architecture |
---|---|
_ReadBarrier |
x86, IPF, x64 |
Header file <intrin.h>
Remarks
The Visual C++ compiler is free to perform any optimization that preserves the meaningful outputs of the program in single-threaded execution. These barriers are provided to block optimization of reads and writes at specific points in a program. This is similar to marking that memory "volatile" only more performant (when usable) because it only forces reads and writes to complete at specific points in a program, rather than globally.
Forcing memory reads to complete ensures that the code generated does not rely on the values of those variables after the call to _ReadBarrier. After a call to _ReadBarrier, other threads can freely modify the variables without fear that the memory might still be read by the thread with the read barrier.
Note In past versions of the compiler, _ReadBarrier was enforced only locally and did not affect functions up the call tree. In Visual C++ 2005, _ReadBarrier is enforced all the way up the call tree.
For a discussion of which variables are exempt from the memory barrier, see_ReadWriteBarrier.
END Microsoft Specific
See Also
Reference
_ReadWriteBarrier
_WriteBarrier
Compiler Intrinsics
C++ Keywords