Mutex class

Mutual exclusion.

The withLock method is a convenience method for acquiring a lock before running critical code, and then releasing the lock afterwards. Using this convenience method will ensure the lock is always released after use.

Usage:

m = Mutex();

await m.withLock(() async {
  // critical section
});

Alternatively, a lock can be explicitly acquired and managed. In this situation, the program is responsible for releasing the lock after it have been used. Failure to release the lock will prevent other code for ever acquiring the lock.

m = Mutex();

await m.lock();
try {
  // critical section
}
finally {
  m.release();
}

Constructors

Mutex()

Properties

hashCode int
The hash code for this object.
no setterinherited
isLocked bool
Indicates if a lock has been acquired and not released.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

lock() Future
Acquire a 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
withLock<T>(Future<T> criticalSection()) Future<T>
Convenience method for protecting a function with a lock.

Operators

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