正在学习c#信号量,有一点不懂。我可以像这样初始化信号量:
var semaphore = new Semaphore(4, 6);
很多地方都有这样的解释:
If you want to reserve some slots for the calling thread, you can do so by making the first parameter smaller than the second.
这是否意味着只有主线程可以使用剩余的 2 个资源槽?这是否意味着如果我这样写:
var semaphore = new Semaphore(0, 6);
只有主线程可以使用所有 6 个插槽?
最佳答案
A semaphore is like a nightclub: it has a certain capacity, enforced by a bouncer. Once it’s full, no more people can enter, and a queue builds up outside. Then, for each person that leaves, one person enters from the head of the queue. The constructor requires a minimum of two arguments: the number of places currently available in the nightclub and the club’s total capacity.
关于c# - 信号量:了解初始和最大请求数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26203040/