Documentation Home >> Headers >> <jss/guards.hpp> Header >> jss::lock_guard class template

The jss::lock_guard class template provides a basic lock ownership wrapper. The type of mutex being locked is specified by template parameter Mutex, and must meet the Lockable requirements. The specified mutex is locked in the constructor and unlocked in the destructor. This provides a simple means of locking a mutex for a block of code and ensuring that the mutex is unlocked when the block is left, whether that is by running off the end, by the use of a control flow statement such as break or return, or by throwing an exception.

Instances of jss::lock_guard are neither MoveConstructible, CopyConstructible or CopyAssignable.

template <class ... LockableTypes>
class lock_guard
    typedef LockableTypes mutex_type; // If LockableTypes is a single type

    explicit lock_guard(LockableTypes& ... m);
    lock_guard(LockableTypes& ... m, adopt_lock_t);

    lock_guard(lock_guard const& ) = delete;
    lock_guard& operator=(
        lock_guard const& ) = delete;

#include <jss/guards.hpp>

See Also