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

NameTypeDescription
_readersi32
_writerbool
_mutexMutex
_read_cvCond
_write_cvCond
impl(RwLock, ...)
new : (RwLock) fn() -> RwLock

Returns: RwLock

read_lock : (RwLock) fn(self : RwLock) -> unit

Parameters

NameTypeNotes
selfRwLock

Returns: unit

read_unlock : (RwLock) fn(self : RwLock) -> unit

Parameters

NameTypeNotes
selfRwLock

Returns: unit

write_lock : (RwLock) fn(self : RwLock) -> unit

Parameters

NameTypeNotes
selfRwLock

Returns: unit

write_unlock : (RwLock) fn(self : RwLock) -> unit

Parameters

NameTypeNotes
selfRwLock

Returns: unit