|
JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
|
Cross-process condition variable primitive (POSIX / Win32). More...
#include <jh/synchronous/ipc/process_cond_var.h>
Public Member Functions | |
| process_cond_var (const process_cond_var &)=delete | |
| process_cond_var & | operator= (const process_cond_var &)=delete |
| void | wait_signal () noexcept |
| Wait until a signal or broadcast occurs. | |
| template<typename Clock, typename Duration> | |
| bool | wait_until (const std::chrono::time_point< Clock, Duration > &tp) noexcept |
| Wait until signaled or a timeout expires. | |
| void | notify_one () noexcept |
| Wake a single waiting process. | |
| void | notify_all (int count=32) noexcept |
| Wake multiple waiting processes (POSIX implementation). | |
Static Public Member Functions | |
| static process_cond_var & | instance () |
| static void | unlink () |
| Remove the condition variable's shared-memory backing (POSIX only). | |
| static void | unlink ()=delete |
| Disabled if HighPriv == false. Non-privileged variants cannot call unlink(). | |
Cross-process condition variable primitive (POSIX / Win32).
Provides a minimal inter-process signaling mechanism modeled after pthread_cond_t. It allows processes to coordinate via named OS-level synchronization objects (shared memory or named events).
pthread_cond_t and pthread_mutex_t stored in shared memory. PTHREAD_PROCESS_SHARED. Event object in the Global\ namespace. notify_all(n) wakes up to n waiting processes (default 32). notify_all() simulates one by setting the event for approximately 1 ms. pthread_mutex_t (POSIX only) protecting access to the condition variable state. process_mutex — ensures one-time
initialization of the shared memory region and condition object attributes
(PTHREAD_PROCESS_SHARED flags, initialized guard, etc.).
The initialization mutex process_mutex is automatically created
within the same namespace as the condition itself. If the user manually declares a
process_mutex elsewhere, it will conflict with the internal
synchronization of process_cond_var. Therefore, avoid defining
any process_mutex with the same template literal S.
unlink(); removes both the shared condition object and the initialization lock.
process_mutex or process_counter for complex protocols.
|
inlinenoexcept |
Wake multiple waiting processes (POSIX implementation).
Signals up to count waiting participants (pthread_cond_signal loop, default 32). Exceeding waiters remain blocked until the next call.
| count | Number of waiting processes to wake (default 32). |
|
inlinenoexcept |
Wake a single waiting process.
Releases exactly one participant blocked in wait_signal() or wait_until().
|
inlinestatic |
Remove the condition variable's shared-memory backing (POSIX only).
shm_unlink() for the condition segment ("/" + S), removing the shared memory region. process_mutex
used for one-time initialization.
Silently ignores ENOENT if the object does not exist. Throws std::runtime_error for other unlink failures.
The process_cond_var internally creates a helper mutex (process_mutex) for initialization coordination.
When unlink() is called, both the shared-memory segment and this mutex are unlinked to prevent stale IPC objects from persisting.
The operation is safe to call multiple times. Once all processes close
their mappings, the system automatically reclaims the resources.
Windows does not support explicit unlink for named event handles.
They are destroyed automatically when the final handle is closed.
|
inlinenoexcept |
Wait until a signal or broadcast occurs.
Blocks the current process until another participant calls notify_one() or notify_all(). Spurious wakeups may occur.
|
inlinenoexcept |
Wait until signaled or a timeout expires.
Suspends execution until the specified absolute time point or until another process issues a notification.
| Clock | Clock type used to measure time (e.g. std::chrono::steady_clock). |
| Duration | Duration type representing the time resolution. |
| tp | Absolute time point until which the caller should wait. |
true if signaled before timeout, otherwise false.