AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AMutexWrapper< T, Lockable > Class Template Reference

Wraps the object with a Lockable, providing exclusive access layer, i.e., for thread-safety. More...

#include <AUI/Thread/AMutexWrapper.h>

Detailed Description

template<typename T, typename Lockable = AMutex>
class AMutexWrapper< T, Lockable >
Template Parameters
TThe type of the value to be protected.
LockableA lockable type which manages locking behaviour, i.e, AMutex.

On debug builds, provides a runtime check for better diagnostics.

Aka boost::synchronized_value.

Implementing thread safety#

struct SharedResource {
  AString data;
};
sharedResource->data = "test"; // bad, will crash
...
// thread 1
std::unique_lock lock(sharedResource); //
sharedResource->data = "hello";        // ok
...
// thread 2
std::unique_lock lock(sharedResource); //
sharedResource->data = "world";        // ok, will be done before or after "hello", but not simultaneously
...
Wraps the object with a Lockable, providing exclusive access layer, i.e., for thread-safety.
Definition AMutexWrapper.h:49
Represents a Unicode character string.
Definition AString.h:38