Class

DispatchSemaphore

An object that controls access to a resource across multiple execution contexts through use of a traditional counting semaphore.

Declaration

class DispatchSemaphore : DispatchObject

Overview

A dispatch semaphore is an efficient implementation of a traditional counting semaphore. Dispatch semaphores call down to the kernel only when the calling thread needs to be blocked. If the calling semaphore does not need to block, no kernel call is made.

You increment a semaphore count by calling the signal() method, and decrement a semaphore count by calling wait() or one of its variants that specifies a timeout.

Topics

Creating a Semaphore

init(value: Int)

Creates new counting semaphore with an initial value.

Signaling the Semaphore

func signal() -> Int

Signals (increments) a semaphore.

Blocking on the Semaphore

func wait()

Waits for, or decrements, a semaphore.

func wait(timeout: DispatchTime) -> DispatchTimeoutResult

Waits for, or decrements, a semaphore.

Relationships

Inherits From

Conforms To

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software