多个线程可以同时等待一个信号量 [英] Multiple threads can wait on a semaphore at same time
本文介绍了多个线程可以同时等待一个信号量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
多个线程可以等待一个信号量吗?如果是,在信号量下降时将恢复哪一个?
Can multiple threads wait on a single semaphore ? If yes, upon semaphore down which one will be resumed ?
推荐答案
Can multiple threads wait on a single semaphore ?
是的.
If yes, upon semaphore down which one will be resumed ?
正是其中之一.哪一个取决于操作系统内核实现:用于保存等待线程的容器类型.这很可能是一个 FIFO 队列,因此第一个调用 semaphore.wait() 的线程将首先被释放,但您不应该以依赖此行为的任何方式设计您的应用.
Exactly one of them. Which one depends on OS kernel implementation: the container type that is used to hold the waiting threads. This is quite likely to be a FIFO queue and so the first thread to call semaphore.wait() will be released first, but you should not design your app in any way that relies on this behaviour.
这篇关于多个线程可以同时等待一个信号量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文