From what I'm reading, semaphores are designed to allow multiple threads to access a pool of resources at the same time. I'm also reading that mutexes only allow a single thread to access a resource a time. I'm currently working with some code that uses a SemaphoreSlim
to ensure that only one thread can access a resource.
Would it ever make sense to create a semaphore, where only a single thread can access the pool of resources at once? In that case, why not use a Mutex
? Or (from what I'm reading) a similar construct in C# - a lock
or a Monitor
? It sounds like mutexes/locks/monitors are simpler, and less potentially-misleading.