How to Implement Semaphores in iOS Application?

前端 未结 4 427
长发绾君心
长发绾君心 2021-02-06 10:52

Is it possible to implement Counting Semaphore in ios application?

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 11:43

    In Swift 3 you can use a DispatchSemaphore.

    // initialization
    let semaphore = DispatchSemaphore(value: initialValue)
    
    // wait, decrement the semaphore count (if possible) or wait until count>0
    semaphore.wait()
    
    // release, increment the semaphore count
    semaphore.signal()
    

提交回复
热议问题