mutex
class is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads.#include <mutex>
std::mutex mutex_name;
mutex_name.lock();
The thread asks for ownership of the shared data protected by the mutex. It can successfully lock the mutex (and then no one else can access the same data) or block if the mutex is already locked by another thread.mutex_name.unlock();
Comments