|
VLink
2.0.0
A high-performance communication middleware
|
Counting semaphore confined to a single process. 更多...
类 | |
| class | vlink::Semaphore |
| In-process counting semaphore with an optional acquire timeout. 更多... | |
命名空间 | |
| vlink | |
Counting semaphore confined to a single process.
vlink::Semaphore offers classic Dijkstra P/V semantics for in-process synchronisation, built on top of std::mutex and the project ConditionVariable (which uses CLOCK_MONOTONIC on Linux so NTP-induced jumps do not skew wait timeouts). It is the right primitive for permit-style throttling, bounded-queue back-pressure, and producer/consumer handoff.
Wait/post interaction between two threads:
* Producer Consumer * | | * | release(n) -- counter+=n ---> | * | | acquire(m): blocks while counter<m * | | counter -= m; resumes *
release() acquires the internal mutex, so it must not be called from a signal handler. Use SysSemaphore or sem_post directly for signal-context posts.reset(true) wakes every blocked waiter and returns false to them; use only during controlled shutdown.