DispatchSemaphore

extension DispatchSemaphore: Locking

A locking construct using a counting semaphore from Grand Central Dispatch. This locking type behaves the same for both read and write locks.

The semaphore lock performs comparably to a spinlock under little lock contention, and comparably to a platform lock under contention.

  • Declaration

    Swift

    public func withReadLock<Return>(_ body: () throws -> Return) rethrows -> Return
  • Declaration

    Swift

    public func withAttemptedReadLock<Return>(_ body: () throws -> Return) rethrows -> Return?