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

ReadWriteMutex()

Properties

isLocked → bool
Indicates if a lock (read or write) has currently been acquired.
read-only
isReadLocked → bool
Indicates if a read lock has currently been acquired.
read-only
isWriteLocked → bool
Indicates if a write lock has currently been acquired.
read-only
hashCode → int
The hash code for this object.
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

acquireRead() → Future
Acquire a read lock [...]
acquireWrite() → Future
Acquire a write lock [...]
release() → void
Release a lock. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

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