C - C++ Threads - Protected access to shared data or shared resources - Atomic Read & Write

Since C++ 11. Also called lockless.

Atomic ensures no races are to be expected while accessing a variable.

NOTE: The syntax can result in a very compact code, which may not be obvious that it actually involves the overhead of atomic operations.

For instance:

some_variable++

The implementation is strongly dependent on the CPU architecture and its support.


Basic Example

Class Example