Dispatch Semaphore

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


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 dispatch_semaphore_signal method, and decrement a semaphore count by calling dispatch_semaphore_wait or one of its variants that specifies a timeout.


Creating a Semaphore


Creates new counting semaphore with an initial value.


A dispatch semaphore object.

Signaling the Semaphore


Signals (increments) a semaphore.

Blocking on the Semaphore


Waits for (decrements) a semaphore.

See Also

Task Synchronization

Dispatch Barrier

A synchronization point for tasks executing in a concurrent dispatch queue.