如果结果值小于零.如果发生超时,请执行此 *** 作
递减是相反的,因此您不必手动调整计数.
从文档中可以看出这一点(对我而言),但与之相符
负数指示线程正在等待的事实
信号.另见the source code中的评论:
// If the internal value is negative,then the absolute of the value is// equal to the number of waiting threads. ...
您也可以通过打印的deBUGDescription来验证它
信号量,输出显示当前值:
let sem = dispatch_semaphore_create(0)NSLog("%@",sem.deBUGDescription)// <OS_dispatch_semaphore: semaphore[0x100514a70] = { ...,value = 0,orig = 0 }>// --> Initial value is 0dispatch_after(dispatch_time(disPATCH_TIME_Now,Int64(NSEC_PER_SEC)),dispatch_get_global_queue(disPATCH_QUEUE_PRIORITY_DEFAulT,0)) { NSLog("%@",sem.deBUGDescription) // <OS_dispatch_semaphore: semaphore[0x100514a70] = { ...,value = -1,orig = 0 }> // --> One thread is waiting,value is -1.}let ret = dispatch_semaphore_wait(sem,dispatch_time(disPATCH_TIME_Now,2*Int64(NSEC_PER_SEC)))NSLog("%@",orig = 0 }>// --> Time out,value is 0 again.总结
以上是内存溢出为你收集整理的ios – 在等待超时时发送信号量信号全部内容,希望文章能够帮你解决ios – 在等待超时时发送信号量信号所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)