Mutexes
A mutex is a mechanism used in concurrency control to prevent race conditions. The function of a mutex is to prevent a thread of execution to enter its critical section at the same time another concurrent thread enters its own critical section. It is a lockable object designed to signal when the critical sections of code need exclusive access, thereby restricting other concurrent threads with the same protection in execution as well as memory access. The C++ 11 standard introduced an std::mutex class into the standard library to achieve data protection across concurrent threads.
The std::mutex class consist of the lock() and unlock() functions to create a critical section in code. One thing to keep in mind while using the member functions ...