Mutex Lock
A MutexLock is a locking mechanism which allows only one thread to gain access to a resource protected by an instance of MutexLock. If more than one thread tries to acquire lock
, only the first thread is successful while the other threads either wait or return depending on whether lock or tryLock was invoked.
Examples
val mutex = MutexLock()
mutex.lock()
assertFalse(mutex.tryLock())
val future = WorkerFactory.newBackgroundWorker().execute(mutex) {
assertFalse(mutex.tryLock())
}
future.await()
mutex.unlock()
mutex.destroy()
class MutexLock
Content copied to clipboard
class MutexLock
Content copied to clipboard