What happens when a counting semaphore initialized to 3 is signaled (V operation) twice after three wait (P) operations have already been performed?
Remember that signaling a counting semaphore increments its value, allowing more processes to enter the critical section.
A counting semaphore initialized to 3 starts with a value of 3. After three wait operations, the value decreases to 0. Two signal operations increment it by 2, resulting in a value of 2. This means two more wait operations can proceed without blocking.
Which of the following statements correctly describes a binary semaphore?
Think about the simplest semaphore used for locking.
A binary semaphore only takes values 0 or 1 and is typically used to ensure that only one process accesses a critical section at a time, enforcing mutual exclusion.
In a producer-consumer problem using semaphores, which semaphore should the consumer wait on before consuming an item?
Consumers can only consume if there is at least one item available.
The consumer must wait on the semaphore that counts full slots to ensure there is an item to consume. Waiting on empty slots or a binary semaphore for mutual exclusion does not guarantee availability of items.
Which of the following semaphore usage patterns can cause a deadlock?
Consider what happens when two processes wait indefinitely for each other.
Deadlock occurs when two or more processes wait forever for resources held by each other, creating a circular wait condition. This happens if each process waits on a semaphore the other holds.
What is the most likely outcome if a binary semaphore used for mutual exclusion is incorrectly initialized to 2 instead of 1?
Think about what happens if the lock allows more than one holder.
If a binary semaphore is initialized to 2, it allows two processes to enter the critical section simultaneously, violating mutual exclusion and potentially causing race conditions.