In new synchronization what is the alternative of DispatchSemaphore?

Asked on 08/17/2024

1 search

In the new synchronization features introduced in Swift, the alternative to DispatchSemaphore is the use of low-level synchronization primitives such as atomics and mutexes. These are part of the synchronization module in Swift, which provides efficient, lock-free implementations for concurrent access. Atomics are generic over any type and should be stored in let properties for safe concurrent access. Mutexes, like atomics, should also be stored in let properties and accessed via the withLock method to ensure mutually exclusive access. This approach is part of Swift's effort to improve data race safety and provide more robust concurrency support.

For more details, you can refer to the session What’s new in Swift (28:43).

In new synchronization what is the alternative of DispatchSemaphore? | Ask WWDC