Creates new counting semaphore with an initial value.


init(value: Int)



The starting value for the semaphore. Do not pass a value less than zero.

Return Value

The newly created semaphore.


Passing zero for the value is useful for when two threads need to reconcile the completion of a particular event. Passing a value greater than zero is useful for managing a finite pool of resources, where the pool size is equal to the value.

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