Questions: Counting Semaphores and Resource Pools

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A counting semaphore is initialized to 3 to govern access to a pool of 3 printers. Two threads each call wait(). A third thread then calls wait(). Now a fourth thread calls wait(). What happens to the fourth thread?

AIt proceeds — the semaphore allows one more thread since it can go to -1
BIt blocks — the semaphore is at 0, indicating no resources are available
CIt causes a deadlock — too many threads called wait()
DIt returns immediately with an error indicating the pool is full
Question 2 Multiple Choice

In a bounded-buffer producer-consumer solution using two counting semaphores (empty=N, full=0), why is a mutex also necessary?

AIt is not necessary — the two counting semaphores already prevent all races
BThe mutex ensures that only one thread runs at a time, which the semaphores cannot do
CThe counting semaphores manage capacity (how many slots), but the buffer data structure itself needs mutual exclusion to prevent concurrent reads and writes from corrupting it
DThe mutex initializes the semaphore values correctly before threads begin
Question 3 True / False

A counting semaphore's internal value can go below zero, with the absolute value representing the number of threads currently blocked waiting for a resource.

TTrue
FFalse
Question 4 True / False

A binary semaphore (mutex) is a special case of a counting semaphore initialized to 1.

TTrue
FFalse
Question 5 Short Answer

Explain why a mutex (binary semaphore) would be inadequate to manage a pool of 10 identical database connections, and how a counting semaphore solves this naturally.

Think about your answer, then reveal below.