|
dispenso 1.6.0
A library for task parallelism
|
#include <distributed_rw_lock.h>
Public Member Functions | |
| void | lock_shared () |
| void | unlock_shared () |
| bool | try_lock_shared () |
| void | lock () |
| bool | try_lock () |
| void | unlock () |
A distributed reader/writer lock compatible with std::shared_mutex.
Uses dispenso::threadId() to pick a sub-lock slot. threadId() is a fast thread-local counter (constant-initialized, lazy-filled on first call) that monotonically distributes threads as 0, 1, 2, ... — masked by N this gives uniform distribution across sub-locks with a single TEB read per call. The lazy-init pattern matters on MSVC, where a static thread_local T x = ... with a non-trivial initializer would generate a per-call TLS init guard.
| N | Number of sub-locks. Must be a power of 2. Higher N = better read scalability under high thread counts, but O(N) write cost. Default 16 balances read distribution vs. write overhead. |
Definition at line 89 of file distributed_rw_lock.h.
|
inline |
Acquire exclusive (write) access.
Definition at line 108 of file distributed_rw_lock.h.
|
inline |
Acquire shared (read) access.
Definition at line 92 of file distributed_rw_lock.h.
|
inline |
Try to acquire exclusive (write) access.
Definition at line 114 of file distributed_rw_lock.h.
|
inline |
Try to acquire shared (read) access.
Definition at line 103 of file distributed_rw_lock.h.
|
inline |
Release exclusive (write) access.
Definition at line 119 of file distributed_rw_lock.h.
|
inline |
Release shared (read) access.
Definition at line 97 of file distributed_rw_lock.h.