Daily bit(e) of C++ | std::lock_guard
Daily bit(e) of C++ #482, A simple RAII mutex lock type: std::lock_guard.
The std::lock_guard is the simplest RAII mutex lock type offered by the standard library.
On construction, a std::lock_guard can either lock the provided mutex or adopt the lock of an already locked mutex. The lock will then be freed on destruction.
std::lock_guard isn't mutable or copyable/movable and can only hold a lock on a single mutex.