Module sync/rwlock
sync/rwlock
Reader-writer lock allowing multiple concurrent readers or one exclusive writer.
Example
{ RwLock } :: import "std/sync/rwlock";
lock := RwLock.new();
// Multiple readers can hold the lock simultaneously
lock.read_lock();
// ... read shared data ...
lock.read_unlock();
// Only one writer at a time, blocks all readers
lock.write_lock();
// ... write shared data ...
lock.write_unlock();
Types
RwLock
atomic object
RwLock
Reader-writer lock built on Mutex and Cond.
Uses atomic reference counting for safe cross-thread sharing.
Fields
| Name | Type | Description |
|---|---|---|
_readers | i32 | |
_writer | bool | |
_mutex | Mutex | |
_read_cv | Cond | |
_write_cv | Cond |
impl(RwLock, ...)
new : (RwLock) fn() -> RwLockReturns: RwLock
read_lock : (RwLock) fn(self : RwLock) -> unitread_unlock : (RwLock) fn(self : RwLock) -> unitwrite_lock : (RwLock) fn(self : RwLock) -> unitwrite_unlock : (RwLock) fn(self : RwLock) -> unit