C - C++ Threads - mutex - Do not use a mutex when std::atomic types will suffice

When using simple data types that needs to be updated, for example, a simple bool or a integer counter, using std::atomic will almost yield better performance than using a mutex.

For example, instead of doing :

int counter;
....
mu.lock();
counter++;
mu.unlock();

Try:

std::atomic<int> counter;
...
counter++;

References

https://www.arangodb.com/2015/02/comparing-atomic-mutex-rwlocks/