1

I'm trying to understand how to use semaphores in c#, I know semaphores accept two parameters when initializing it Semaphore(initial count, maximum count). But I don't fully understand what the parameters mean. Here's an analogy I'm using to understand it

Imagine a bathroom with only one stall so that way it's only possible for one person to use it at a time. There's a queue outside the bathroom. using this analogy can you explain what the initial count and maximum count mean.

Casper Josh
  • 31
  • 1
  • 6
  • Related: [Semaphore - What is the use of initial count?](https://stackoverflow.com/questions/4706734/semaphore-what-is-the-use-of-initial-count) – Theodor Zoulias Mar 25 '22 at 12:20
  • The related question linked above has a great answer that should be read, but I can't help feeling that this analogy (and the accepted answer here) is the easiest way of thinking about this. – bornfromanegg Jun 14 '23 at 12:03

1 Answers1

4

Maximum count is the available number of stalls in your bathroom and initial count is the number of currently available stalls in your bathroom.

Clemens
  • 588
  • 6
  • 9