Conditional variable for synchronization.
More...
#include "nn/nlib/threading/CondVar.h"
Conditional variable for synchronization.
- Description
- Used to wake a thread when the shared data meets some condition.
Waits with the Wait
function until the conditions are met. When the conditions are met, threads are awakened by Notify
and NotifyAll
.
- The functionality is the same as
CONDITION_VARIABLE
in Windows or pthread_cond
.
SimpleCriticalSection m;
bool flag;
if (!cond.Initialize()) { error; }
....
m.lock();
while (!flag) {
if (e != 0) { ERROR; }
}
....
flag = false;
m.unlock();
Definition at line 34 of file CondVar.h.
nn::nlib::threading::CondVar::Notify |
( |
| ) |
|
|
inlinenoexcept |
Signals to at least one waiting thread.
- Description
- We recommend using
NotifyAll
, as some threads may not be able to receive a signal for a extended period of time.
Definition at line 50 of file CondVar.h.
template<class lock_type >
nn::nlib::threading::CondVar::Wait |
( |
lock_type & |
lock | ) |
|
|
inlinenoexcept |
Waits.
- Parameters
-
[in,out] | lock | Class like CriticalSection that includes the lock and unlock member functions. |
- Return values
-
0 | An error has not occurred. |
ENOMEM | Indicates that there are not enough system resources. |
Definition at line 64 of file CondVar.h.
template<class lock_type >
nn::nlib::threading::CondVar::WaitFor |
( |
lock_type & |
lock, |
|
|
const nlib_ns::TimeSpan & |
timeout |
|
) |
| |
|
inlinenoexcept |
Waits with a specified timeout.
- Parameters
-
[in,out] | lock | Class like CriticalSection that includes the lock and unlock member functions. |
[in] | timeout | Specifies the timeout. |
- Return values
-
0 | An error has not occurred. |
ETIMEDOUT | Indicates a timeout. |
ENOMEM | Indicates that there are not enough system resources. |
Definition at line 73 of file CondVar.h.
template<class lock_type >
nn::nlib::threading::CondVar::WaitUntil |
( |
lock_type & |
lock, |
|
|
const nlib_ns::DateTime & |
datetime |
|
) |
| |
|
inlinenoexcept |
Waits with a timeout specified in date/time.
- Parameters
-
[in,out] | lock | Class like CriticalSection that includes the lock and unlock member functions. |
[in] | datetime | Timeout limit. |
- Return values
-
0 | An error has not occurred. |
ETIMEDOUT | Indicates a timeout. |
ENOMEM | Indicates that there are not enough system resources. |
Definition at line 77 of file CondVar.h.
The documentation for this class was generated from the following files: