The std::mutex also has a std::lock_guard class. It is much better to use a lock_guard since it protects you from exceptions being thrown (since the destructor of the lock_guard will release the lock).