Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lvalue argument for dispatch_semaphore_create ?

What does the long value parameter signify in dispatch_semaphore_create ?

dispatch_semaphore_create(long value)

I didn't see this in the documentation, only examples of it being used with a zero argument.

like image 751
Jasper Blues Avatar asked Sep 25 '13 03:09

Jasper Blues


1 Answers

The value parameter is the initial value for the counting semaphore.

dispatch_semaphore_wait() decrements the semaphore count and waits if the resulting value is less than 0 (i.e. you can call dispatch_semaphore_wait four times without waiting on a semaphore created with value 4).

dispatch_semaphore_signal() increments the semaphore count and wakes a waiter if the resulting value is less than or equal 0.

See the dispatch_semaphore_create(3) manpage for a typical usage example (managing a finite resource pool).

like image 133
das Avatar answered Oct 14 '22 05:10

das