File locked_condition_variable.hpp¶
All templated types in this namespaces are elementary types: int, double, float, char*, …
Typedefs
- #include <locked_condition_variable.hpp>
The LockedConditionVariable class is here as a anonymous layer on top of the boost intersprocess condition variable labrary.
It creates a condition variable in a shared memory automatically.
Public Functions
A condition variable shared over the memory The condition variable is cleaned from the memory on destruction if clean_memory_on_destruction is set to true.
Contrary to shared_memory::ConditionVariable, instances of this class manages their mutex and lock internally, with the consequence the mutex can be locked and unlocked exclusively through other instances of LockedConditionVariable.
notify_all is notifying all condition variables with the same mutex
notify_one notifies one condition variable with the same mutex
wait waits until another thread notifies this object
timed_wait wait a notify during a certain certain time and then wake up
- Parameters:
wait_duration – in microsecond
- Returns:
true: the condition variable has been notified, false otherwize
try_lock Tries to acquire the lock without waiting.
- Throws :
- Returns:
true if manages to acquire the lock, false otherwise.
unlock Unlocks the lock.
- Throws :
lock_scope this function is used to lock the part of the code that needs protection.
It locks the mutex until unlock_scope is used
unlock_scope this function unlock the mutex so remove the protection of the code
Public Members
mutex_ is the mutex associated to the condition variable
condition_variable_ is the boost condition variable that is used
lock_ is a object that protects the codes with a mutex, see the boost documentation about “boost::interprocess::scoped_lock”
if true (the default), clean the shared memory of the hosted mutex and condition.
Public Static Functions
LockedConditionVariable clean their shared memory on destruction.
But the destructor may have failed to be called if for some reason the program crashed.
Private Members
mutex_id_ is the mutex name in the shared memory
condition_id_ is the condition variable name in the shared memory
shm_segment is the boost object that manages the shared memory segment