VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
sys_semaphore.h 文件参考

Named, cross-process counting semaphore backed by the OS IPC layer. 更多...

#include <memory>
#include <string>
#include "./macros.h"
sys_semaphore.h 的引用(Include)关系图:

浏览该文件的源代码.

 Named cross-process counting semaphore. 更多...

命名空间

详细描述

Named, cross-process counting semaphore backed by the OS IPC layer.

SysSemaphore wraps a named POSIX semaphore (on Linux/macOS) or a named Win32 semaphore to allow synchronisation between independent processes (or between processes and drivers) via a shared name in the OS namespace.

Lifecycle:

  1. Construct the SysSemaphore object.
  2. Call attach(name) to create or open a named semaphore.
  3. Use acquire() / release() for P/V operations.
  4. Call detach(force) to close the handle. If force is true the semaphore is also removed from the OS namespace.
  5. The destructor calls detach() automatically.
注解
  • The initial count passed to the constructor is only used when the semaphore is created by attach(). If the semaphore already exists in the OS namespace the constructor count is ignored and the existing value is used.
  • Unlike Semaphore, this class may throw on attach() failures (e.g., permission denied, namespace exhausted).
  • Semaphore names on POSIX must start with '/' (e.g., "/vlink_ready"). On Windows any non-empty string is accepted.
Example
// Process A (server) creates the semaphore:
sem.attach("/vlink_ready");
do_init();
sem.release(); // signal Process B
// Process B (client) opens the same semaphore:
sem.attach("/vlink_ready");
sem.acquire(); // blocks until Process A releases