ReadWriteMutex class
Mutual exclusion that supports read and write locks.
Multiple read locks can be simultaneously acquired, but at most only one write lock can be acquired at any one time.
Create the mutex:
m = new ReadWriteMutex();
Some code can acquire a write lock:
await m.acquireWrite();
try {
// critical write section
assert(m.isWriteLocked);
}
finally {
m.release();
}
Other code can acquire a read lock.
await m.acquireRead();
try {
// critical read section
assert(m.isReadLocked);
}
finally {
m.release();
}
The current implementation lets locks be acquired in first-in-first-out order. This ensures there will not be any lock starvation, which can happen if some locks are prioritised over others. Submit a feature request issue, if there is a need for another scheduling algorithm.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isLocked → bool
-
Indicates if a lock (read or write) has currently been acquired.
no setter
- isReadLocked → bool
-
Indicates if a read lock has currently been acquired.
no setter
- isWriteLocked → bool
-
Indicates if a write lock has currently been acquired.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
acquireRead(
) → Future - Acquire a read lock
-
acquireWrite(
) → Future - Acquire a write lock
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
release(
) → void - Release a lock.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited