|
VLink
2.0.0
A high-performance communication middleware
|
Monotonic-clock condition variable replacement immune to system clock jumps. More...
#include <condition_variable>Go to the source code of this file.
Namespaces | |
| vlink | |
Typedefs | |
| using | vlink::ConditionVariable = std::condition_variable |
| using | vlink::ConditionVariableAny = std::condition_variable_any |
| using | vlink::condition_variable = ConditionVariable |
| using | vlink::condition_variable_any = ConditionVariableAny |
Monotonic-clock condition variable replacement immune to system clock jumps.
Older libstdc++ implementations route every std::condition_variable timed wait through CLOCK_REALTIME, so an NTP step or manual date change can spuriously wake or starve waiters (GCC PR 41861 / DR 887). On POSIX systems this header substitutes a hand-rolled vlink::ConditionVariable backed by a pthread_cond_t configured with pthread_condattr_setclock (..., CLOCK_MONOTONIC). On Windows the bug does not apply and the names alias to the standard library types verbatim.
std::condition_variable | Aspect | std::condition_variable | vlink::ConditionVariable |
|---|---|---|
| Backing clock | CLOCK_REALTIME (libstdc++) | CLOCK_MONOTONIC via pthread_condattr |
| Timed waits | Sensitive to wall clock jumps | Immune to wall clock jumps |
| Copy / move | Deleted | Deleted |
| Public methods | wait / wait_for / wait_until / notify_* | Same signatures, same return types |
| Native handle | pthread_cond_t* | pthread_cond_t* |
* producer thread consumer thread * --------------- --------------- * lock(mtx) lock(mtx) * state = ready cv.wait(lock, predicate) * unlock(mtx) releases mtx, blocks * cv.notify_one() -----------> wakes; reacquires mtx * re-checks predicate * returns to caller *
Both ConditionVariable and ConditionVariableAny accept any std::chrono clock type; non-steady clock arguments are projected onto steady_clock at entry and re-checked at exit for timeout fidelity. Convenience type aliases vlink::condition_variable and vlink::condition_variable_any are also exposed.