std::atomic<T> template allows thread safe writing, reading and incrementing numeric values.

Reading and writing memory from different threads leads to data races and unpredictable results.

std::atomic adds necessary barriers to make the operations thread safe.

Example of using std::atomic_int:

https://codeeval.dev/gist/a3be0f9c9552fff392e9567f15094160

std::atomic<T> specialization in standard library