/*!
* @function dispatch_semaphore_wait
*
* @abstract
* Wait (decrement) for a semaphore.
*
* @discussion
* Decrement the counting semaphore. If the resulting value is less than zero,
* this function waits for a signal to occur before returning.
*
* @param dsema
* The semaphore. The result of passing NULL in this parameter is undefined.
*
* @param timeout
* When to timeout (see dispatch_time). As a convenience, there are the
* DISPATCH_TIME_NOW and DISPATCH_TIME_FOREVER constants.
*
* @result
* Returns zero on success, or non-zero if the timeout occurred.
*/
intptr_t dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout);
操作:
1、对信号量进行-1
2、判断当前信号量是否小于0,注意是小于0
3、返回0,则不阻塞,非0则阻塞当前线程(超时可继续执行)
作用:
1、方法对信号量-1
2、对信号量-1操作之后,如果信号量小于0,则等待,直到信号量大于等于0