Mutex class

Mutual exclusion.

The protect 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.protect(() 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.acquire();
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

acquire() Future
Acquire a lock
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
protect<T>(Future<T> criticalSection()) Future<T>
Convenience method for protecting a function with a lock.
release() → void
Release a lock.
toString() String
A string representation of this object.
inherited

Operators

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