Welcome to the new CppUtils documentation!
CppUtils::Thread::MultipleAccessor<class... Lockers>
STRUCTRAII structure locking multiple lockers simultaneously without deadlocks.
Description
Section titled “Description”Uses std::scoped_lock internally to acquire all locks atomically in a deadlock-free manner, regardless of the order lockers are passed across different threads.
auto account0 = CppUtils::Thread::UniqueLocker<Account>{};auto account1 = CppUtils::Thread::UniqueLocker<Account>{};
{ auto lockBoth = CppUtils::Thread::MultipleAccessor{account0, account1}; auto& [firstAccount, secondAccount] = lockBoth.values; firstAccount.withdraw(100); secondAccount.deposit(100);}| Template parameter | Description |
|---|---|
Lockers | Variadic list of locker types to lock simultaneously. |
Public methods & functions
Section titled “Public methods & functions”Locks all provided lockers atomically.
| Parameter | Description |
|---|---|
lockers | Variadic references to lockers to lock. |
Public attributes
Section titled “Public attributes”values
Section titled “values”std::tuple< decltype(std::declval< Lockers >().m_value)&... > values;