|
BDE 4.14.0 Production release
|
Macros | |
| #define | BSLS_BSLLOCK_ASSERT_SAFE(x) |
Provide a platform-independent mutex for use below bslmt.
BslLockThis component provides a mutually exclusive lock primitive ("mutex") by wrapping a suitable platform-specific mechanism. The bsls::BslLock class provides lock and unlock operations. Note that bsls::BslLock is not intended for direct client use; see bslmt_mutex instead. Also note that bsls::BslLock is not recursive.
This component also provides the bsls::BslLockGuard class, a mechanism that follows the RAII idiom for automatically acquiring and releasing the lock on an associated bsls::BslLock object. To ensure exception safety, client code should make use of a bsls::BslLockGuard object wherever appropriate rather than calling the methods on the associated bsls::BslLock object directly.
In this section we show intended use of this component.
In this example we illustrate the use of bsls::BslLock and bsls::BslLockGuard to write a thread-safe class.
First, we provide an elided definition of the my_Account class. Note the d_lock data member of type bsls::BslLock:
Next, we show the implementation of the two my_Account manipulators show-casing the use of bsls::BslLock and bsls::BslLockGuard:
Here, we use the interface of bsls::BslLock directly. However, wherever appropriate, a bsls::BslLockGuard object should be used instead to ensure that an acquired lock is always properly released, even if an exception is thrown:
In contrast, withdraw uses a bsls::BslLockGuard to automatically acquire and release the lock. The lock is acquired as a side-effect of the construction of guard, and released when guard is destroyed upon returning from the function:
| #define BSLS_BSLLOCK_ASSERT_SAFE | ( | x | ) |