Can we use locks with Swift Concurrency?

Asked on 07/30/2024

1 search

Yes, you can use locks with Swift Concurrency. The synchronization module in Swift introduces low-level primitives such as atomics and mutexes. A mutex can be stored in a let property and accessed safely concurrently. All accesses to the storage protected by the mutex are done via the closure passed to the withLock method, ensuring mutually exclusive access.

For more details, you can refer to the session What’s new in Swift at the timestamp 28:51.