Skip to content
Welcome to the new CppUtils documentation!

Monitor Object wrapper providing shared read / exclusive write synchronization.

Encapsulates a resource with a std::shared_mutex, allowing either multiple concurrent read-only accessors (via sharedAccess()) or a single exclusive read-write accessor (via uniqueAccess()).

Template parameterDescription
TType of the protected resource.
using CppUtils::Thread::SharedLocker< T >::UniqueAccessor = Accessor<T, SharedMutex>;
using CppUtils::Thread::SharedLocker< T >::SharedAccessor = ReadOnlyAccessor<T, SharedMutex>;
constexpr SharedLocker::SharedLocker() requires std::default_initializable<T> = default;

explicit constexpr SharedLocker::SharedLocker(auto&& first, auto&&... rest);

Constructs the protected resource in place.

ParameterDescription
firstFirst argument forwarded to the resource constructor.
restRest of arguments forwarded to the resource constructor.

SharedLocker::SharedLocker(const SharedLocker&) = delete;

auto SharedLocker::operator=(const SharedLocker&) -> SharedLocker& = delete;

constexpr SharedLocker::SharedLocker(SharedLocker&& other) noexcept(std::is_nothrow_move_constructible_v<T>);

Move constructor. Acquires lock on the source locker before moving its value.


constexpr auto SharedLocker::operator=(SharedLocker&& other) noexcept(std::is_nothrow_move_assignable_v<T>) -> SharedLocker&;

Move assignment. Acquires scoped lock on both mutexes before moving the value.


[[nodiscard]] constexpr auto SharedLocker::uniqueAccess() -> UniqueAccessor;

Acquires exclusive read/write access.

Returns: UniqueAccessor holding a unique lock.


[[nodiscard]] constexpr auto SharedLocker::sharedAccess() const -> SharedAccessor;

Acquires shared read-only access.

Returns: SharedAccessor holding a shared lock.