Mutex
struct · iOS 18.0+ · SDK 27.1
@frozen struct Mutex<Value> where Value : ~CopyableA synchronization primitive that protects shared mutable state via mutual exclusion. The `Mutex` type offers non-recursive exclusive access to the state it is protecting by blocking threads attempting to acquire the lock. Only one execution context at a time has access to the value stored within the `Mutex` allowing for exclusive access. An example use of `Mutex` in a class used simultaneously by many threads protecting a `Dictionary` value: class Manager { let cache = Mutex<[Key: Resource]>([:]) func saveResource(_ resource: Resource, as key: Key) { cache.withLock { $0[key] = resource } } }
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
Mutex.init(_:)
The iOS SDK compiler rejected this binding: instance method 'out' requires that 'Mutex<Any>' be a class type
Mutex.withLock(_:)
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'Mutex<Any>' conform to 'Copyable'
Mutex.withLockIfAvailable(_:)
The iOS SDK compiler rejected this binding: instance method 'receiver()' requires that 'Mutex<Any>' conform to 'Copyable'