gpt4 book ai didi

c# - 信号量:了解初始和最大请求​​数

转载 作者:太空宇宙 更新时间:2023-11-03 18:29:12 24 4
gpt4 key购买 nike

正在学习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 个插槽?

最佳答案

我喜欢Albahari's explanation :

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com