Lvalue argument for dispatch_semaphore_create?

What does the long value parameter in dispatch_semaphore_create mean?

dispatch_semaphore_create(long value) 

I have not seen this in the documentation, only examples of its use with a null argument.

+6
source share
1 answer

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

dispatch_semaphore_wait() decreases the semaphore counter and waits if the resulting value is less than 0 (i.e. you can call dispatch_semaphore_wait four times without waiting for the semaphore created with value 4).

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

See the dispatch_semaphore_create(3) man page for a typical use case (managing a finite resource pool).

+9
source

Source: https://habr.com/ru/post/954552/


All Articles