PosixLock
public final class PosixLock : LockingProtocol
A mutually exclusive (or mutex) lock.
A mutex is a type of semaphore that grants access to only one thread at a time. If a mutex is in use and another thread tries to acquire it, that thread blocks until the mutex is released by its original holder. If multiple threads compete for the same mutex, only one at a time is allowed access to it.
You instantiate a re-entrant variant by passing true
to init(recursive:)
.
A recursive lock may be acquired multiple times by the same thread without
causing a deadlock, a situation where a thread is permanently blocked waiting
for itself to relinquish a lock. While the locking thread has one or more
locks, all other threads are prevented from accessing the code protected by
the lock.
Both types of locks check for usage errors. See PTHREAD_MUTEX_ERRORCHECK
and PTHREAD_MUTEX_RECURSIVE
in man 3 pthread_mutexattr_settype
.
Backed by pthread_mutex
.
-
Declaration
Swift
@inlinable public init(recursive: Bool = false)
-
Declaration
Swift
@inlinable public func tryAcquire() -> Bool
-
Declaration
Swift
@inlinable public func acquire()
-
Declaration
Swift
@inlinable public func release()