http://msdn.microsoft.com/en-us/library/system.threading.semaphoreslim.aspx
To create a semaphore, I need to specify an initial counter and a maximum quantity. MSDN claims the start counter is
The initial number of queries for a semaphore that can be provided at the same time.
While it is indicated that the maximum quantity
The maximum number of queries for a semaphore that can be provided simultaneously.
I can understand that the maximum number is the maximum number of threads that can access the resource at the same time. But what is the use of an initial account?
If I create a semaphore with an initial number of 0 and a maximum of 2, none of my stream threads will be able to access the resource. If I set the initial count as 1, and the maximum number is 2, then the resource stream of the thread can access the resource. Only when I set both the initial count and the maximum count as 2, 2 threads can simultaneously access the resource. So, am I really confused about the value of the original account?
SemaphoreSlim semaphoreSlim = new SemaphoreSlim(0, 2);
multithreading c # concurrency semaphore
Sandbox Jan 16 '11 at 17:03 2011-01-16 17:03
source share