I'm learning c# semaphore and don't understand one point. I can initialize Semaphore like this:
var semaphore = new Semaphore(4, 6);
There is such explanation in many places:
If you want to reserve some slots for the calling thread, you can do so by making the first parameter smaller than the second.
Does it mean that only main thread can use remaining 2 resource slots? Does it mean that if I write like this:
var semaphore = new Semaphore(0, 6);
only main thread can use all 6 slots?
I like 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With