now writing complicated class
and felt that I use to much CRITICAL_SECTION
.
As far as I know there are atomic operations for some types, th
Note: This answer applies to Windows and says nothing of other platforms.
There are no InterlockedRead or InterlockedWrite functions; simple reads and writes with the correct integer size (and alignment) are atomic on Windows ("Simple reads and writes to properly-aligned 32-bit variables are atomic operations.").
(and there are no cache problems since a properly-aligned variable is always on a single cache line).
However, reading and modifying such variables (or any other variable) are not atomic:
bool
? Fine. Test-And-Set a bool
? Better use
InterlockedCompareExchange.