std::atomic (C++)
Wow I am so uneducated about the Multithreading world.
There are conditions when an object is at the same time accessed by different threads, resulting in an undefined behavior. This situation is called Data race.
C++ has an Atomic Type to solve this problem of Data Race.
[question] Why
std::atomicwhen you havestd::mutex??
std::atomicprovides a more lightweight and efficient mechanism for concurrency when dealing with simple data, whereasstd::mutexoffers broader control over critical sections but comes with more overhead.
Resources