本片文字意在记录gcd的一些用法
1. dispatch_semaphore
相关方法:
dispatch_semaphore_create() //创建信号量,设置能同时执行的最大线程数
dispatch_semaphore_wait() //信号量-1
dispatch_semaphore_signal() //信号量+1
dispatch_semaphore_wait方法:
Decrement the counting semaphore. If the resulting value is less than zero, this function waits for a signal to occur before returning.
信号量减1,如果结果小于0,会阻塞当前线程等待新信号的出现。
如果为DISPATCH_TIME_FOREVER,则会一直等待
dispatch_semaphore_signal方法:
Increment the counting semaphore. If the previous value was less than zero, this function wakes a thread currently waiting in dispatch_semaphore_wait
信号量加1,如果之前的信号量小于0,则会唤醒dispatch_semaphore_wait方法中等待着的线程
使用的方法:先降后升