Explain Semaphores and how they differ from Mutexes.

Updated Apr 28, 2026

Short answer

A Semaphore maintains a set of permits. Unlike a Mutex (binary), a Counting Semaphore allows a specific number of threads to access a resource.

Deep explanation

Mid-level concurrency focuses on coordination patterns. The goal is to move beyond simple 'locks' and use high-level abstractions provided by the language or framework (like Thread Pools) to ensure scalability.

Real-world example

A database connection pool limiting the number of simultaneous connections to 20.

Common mistakes

  • Using a heavy Mutex for a scenario where 99% of operations are Reads.

Follow-up questions

  • What is the 'Condition' variable in a lock?

More Concurrency interview questions

View all →