Questions: Semaphores

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A parent thread must wait until a child thread finishes initialization before proceeding. Which approach is most appropriate?

AA mutex initialized to locked — the parent acquires the lock and the child releases it after finishing
BA semaphore initialized to 0 — the parent calls wait (blocking), and the child calls signal after initialization completes
CA mutex initialized to unlocked — the parent polls in a loop until it can acquire the lock
DA semaphore initialized to 1 — both threads call wait, and whichever succeeds first proceeds
Question 2 Multiple Choice

A bounded buffer holds up to 5 items. You use a counting semaphore 'empty' (initialized to 5) and 'full' (initialized to 0). A producer wants to insert an item. What is the correct sequence?

ASignal 'empty', insert the item, then signal 'full'
BWait on 'full', insert the item, then signal 'empty'
CWait on 'empty', insert the item, then signal 'full'
DWait on both 'empty' and 'full' before inserting
Question 3 True / False

A binary semaphore and a mutex are functionally identical because both restrict access to one thread at a time.

TTrue
FFalse
Question 4 True / False

Calling signal (V) on a semaphore when no threads are blocked still increments the counter, effectively saving the signal as a credit for a future wait call.

TTrue
FFalse
Question 5 Short Answer

Why is it correct to say semaphores 'generalize' mutexes rather than simply being a different kind of lock?

Think about your answer, then reveal below.