OGeek|极客世界-中国程序员成长平台

标题: ios - 除了 API 之外,iOS 中的 NSCondition 和 dispatch_semaphore 有什么区别? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:27
标题: ios - 除了 API 之外,iOS 中的 NSCondition 和 dispatch_semaphore 有什么区别?

它们都使用计数器,并使用锁来保护计数器的递增和递减,当计数器小于零时,线程等待。在我看来,除了它们的 api 之外,它们是相同的。



Best Answer-推荐答案


Apple 在他们的文档中写到关于 DispatchSemaphore signal() 方法:

this function wakes a thread currently waiting in dispatch_semaphore_wait(:.

DispatchSemaphore 不同,NSCondition 有 2 种不同的方法:

1) 广播():

Signals the condition, waking up all threads waiting on it.

2) 信号()

Signals the condition, waking up one thread waiting on it.

关于ios - 除了 API 之外,iOS 中的 NSCondition 和 dispatch_semaphore 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43306625/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4