ReadWriteLock class

A reader/writer lock with read/write scopes. Reentrancy is NOT supported (acquiring a write inside a read on the same lock will deadlock).

Constructors

ReadWriteLock({bool writerPreferred = true})
Creates a lock. writerPreferred (default true) makes waiting writers take priority over newly-arriving readers. Audited: 2026-06-12 11:26 EDT

Properties

activeReaders → int
Number of readers currently holding the lock. Audited: 2026-06-12 11:26 EDT
no setter
hashCode → int
The hash code for this object.
no setterinherited
isWriteLocked → bool
Whether a writer currently holds the lock exclusively. Audited: 2026-06-12 11:26 EDT
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
waitingReaders → int
Readers currently waiting to acquire. Audited: 2026-06-12 11:26 EDT
no setter
waitingWriters → int
Writers currently waiting to acquire. Audited: 2026-06-12 11:26 EDT
no setter
writerPreferred → bool
Whether a waiting writer blocks newly-arriving readers (anti-starvation). Audited: 2026-06-12 11:26 EDT
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read<T>(Future<T> action()) → Future<T>
Runs action under a shared read lock, releasing it afterward even if action throws. Multiple reads run concurrently. Audited: 2026-06-12 11:26 EDT
toString() → String
A string representation of this object.
override
write<T>(Future<T> action()) → Future<T>
Runs action under the exclusive write lock, releasing it afterward even if action throws. No reads or other writes overlap it. Audited: 2026-06-12 11:26 EDT

Operators

operator ==(Object other) → bool
The equality operator.
inherited