🎓 BookMCQ
← Back to 5. Process Synchronization

📝 Semaphore Usage (56 MCQs)

📖 From Operating System • 5. Process Synchronization • 56 questions available

What is Semaphore Usage?

Definition:
Semaphore usage encompasses applying binary semaphores for mutual exclusion and counting semaphores for signaling between cooperating processes to enforce execution ordering.

Example:
Process AA performs signal(S)signal(S) after producing data, while process BB performs wait(S)wait(S) before consuming, ensuring consumeconsume happens only after produceproduce.

Reason:
Proper usage decouples producer-consumer logic and enforces precedence constraints without busy-waiting, enabling efficient inter-process communication and coordination.

20
Easy
28
Medium
8
Hard

📝 All Semaphore Usage MCQs

Q1. What is the value range of a counting semaphore?

A.Only 0 and 1.
B.Any non-negative integer. ✅
C.Only positive integers.
D.Any integer including negative values.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A counting semaphore can range over an unrestricted domain, typically any non-negative integer. This allows it to represent the number of available resources, which can be any value from 0 up to the total number of resources.

Q2. What is the value range of a binary semaphore?

A.0 to 1. ✅
B.Any non-negative integer.
C.-1 to 1.
D.0 to n where n is the number of processes.
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: A binary semaphore can range only between 0 and 1. This restriction makes it behave similarly to a mutex lock, where 1 indicates the lock is available and 0 indicates it is held by a process.

Q3. How does a binary semaphore compare to a mutex lock?

A.A binary semaphore is more powerful than a mutex lock.
B.A binary semaphore behaves similarly to a mutex lock. ✅
C.A binary semaphore is less efficient than a mutex lock.
D.A binary semaphore can only be used for counting resources.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Binary semaphores behave similarly to mutex locks. Both are used for mutual exclusion and have only two states: available (1) and unavailable (0). In systems without mutex locks, binary semaphores can be used as a substitute.

Q4. What is the primary use of a counting semaphore?

A.To enforce mutual exclusion.
B.To control access to a finite number of resources. ✅
C.To implement busy waiting.
D.To prevent deadlocks.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Counting semaphores are primarily used to control access to resources that have multiple instances. The semaphore value represents the number of available resources, allowing multiple processes to access different instances of the resource concurrently.

Q5. How is a counting semaphore initialized when managing n identical resources?

A.To 0.
B.To 1.
C.To n. ✅
D.To -n.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: When using a counting semaphore to manage n identical resources, the semaphore is initialized to n. This represents the total number of available resources. Each `wait()` operation decrements the count as a resource is acquired.

Q6. What happens when a process executes `wait()` on a counting semaphore with value 0?

A.The process continues execution.
B.The process blocks until the semaphore value becomes positive. ✅
C.The semaphore value becomes -1.
D.The process is terminated.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a process executes `wait()` on a counting semaphore with value 0, all resources are in use. The process blocks (or busy-waits) until the semaphore value becomes greater than 0, indicating that a resource has been released.

Q7. What operation is performed when a process acquires a resource managed by a counting semaphore?

A.`signal()` on the semaphore.
B.`wait()` on the semaphore. ✅
C.`acquire()` on the semaphore.
D.`release()` on the semaphore.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a process wishes to use a resource, it performs a `wait()` operation on the semaphore. This decrements the semaphore count, indicating that one resource is now in use. If resources are available, the process proceeds.

Q8. What operation is performed when a process releases a resource managed by a counting semaphore?

A.`wait()` on the semaphore.
B.`signal()` on the semaphore. ✅
C.`acquire()` on the semaphore.
D.`block()` on the semaphore.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a process releases a resource, it performs a `signal()` operation on the semaphore. This increments the semaphore count, indicating that a resource has been freed and is now available for other processes to use.

Q9. What is the effect of `wait()` on a counting semaphore?

A.It increments the semaphore value.
B.It decrements the semaphore value. ✅
C.It sets the semaphore value to 0.
D.It sets the semaphore value to 1.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The `wait()` operation decrements the semaphore value. This is how a process acquires a resource, reducing the count of available resources by one. If the value is already 0, the process blocks until resources become available.

Q10. What is the effect of `signal()` on a counting semaphore?

A.It decrements the semaphore value.
B.It increments the semaphore value. ✅
C.It sets the semaphore value to 0.
D.It sets the semaphore value to 1.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The `signal()` operation increments the semaphore value. This is how a process releases a resource, increasing the count of available resources by one. This may unblock a waiting process.

Q11. How can a binary semaphore be used to provide mutual exclusion?

A.By initializing it to 0.
B.By initializing it to 1. ✅
C.By initializing it to the number of processes.
D.By using it only for counting.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A binary semaphore is initialized to 1 to provide mutual exclusion. A process calls `wait()` to acquire the semaphore (setting it to 0) before entering its critical section and `signal()` to release it (setting it back to 1) after exiting. This ensures only one process is in the critical section at a time.

Q12. What is the key difference between a binary and a counting semaphore?

A.A binary semaphore can only be used by two processes.
B.A counting semaphore can have a value greater than 1. ✅
C.A binary semaphore is faster.
D.A counting semaphore cannot be used for mutual exclusion.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The key difference is the range of values. A binary semaphore can only be 0 or 1, while a counting semaphore can have any non-negative integer value. This allows counting semaphores to manage multiple resources, whereas binary semaphores are limited to mutual exclusion.

Q13. What does the count of a counting semaphore represent?

A.The number of processes waiting.
B.The number of available resources. ✅
C.The priority of the processes.
D.The time since initialization.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The count of a counting semaphore represents the number of available resources. When the count is n, n resources are available. When the count is 0, all resources are in use. This is the fundamental principle behind resource management with semaphores.

Q14. What happens to a process that calls `wait()` on a semaphore with count 0?

A.It continues to execute normally.
B.It blocks until the count becomes greater than 0. ✅
C.It decrements the count to -1 and continues.
D.It is immediately terminated.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a process calls `wait()` on a semaphore with count 0, it cannot proceed because no resources are available. The process blocks (either busy-waits or is put to sleep) until the count becomes greater than 0, which happens when some other process releases a resource with `signal()`.

Q15. Which type of semaphore is typically used to solve the critical-section problem?

A.Counting semaphore.
B.Binary semaphore. ✅
C.Both binary and counting semaphores.
D.Neither type.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A binary semaphore is typically used to solve the critical-section problem because it provides mutual exclusion. It is initialized to 1 and acts exactly like a mutex lock, ensuring only one process can enter the critical section at a time.

Q16. In the synchronization problem where S2 must execute after S1, what is the initial value of the semaphore?

A.1
B.0 ✅
C.-1
D.Any positive integer.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The semaphore is initialized to 0. This ensures that P2, which calls `wait(synch)`, will block because the semaphore value is 0. P1 will execute S1, then call `signal(synch)`, incrementing the value to 1. Only then can P2 proceed through its `wait()` and execute S2.

Q17. In the synchronization problem where S2 must execute after S1, which process calls `signal(synch)`?

A.P1 only. ✅
B.P2 only.
C.Both P1 and P2.
D.Neither process.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Process P1 calls `signal(synch)` after executing S1. This operation increments the semaphore from 0 to 1, allowing P2 to proceed past its `wait(synch)` call and execute S2. This ensures the correct ordering of statements.

Q18. In the synchronization problem where S2 must execute after S1, which process calls `wait(synch)`?

A.P1 only.
B.P2 only. ✅
C.Both P1 and P2.
D.Neither process.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Process P2 calls `wait(synch)` before executing S2. Since the semaphore is initialized to 0, P2 will block. It will only proceed after P1 executes S1 and calls `signal(synch)`, which increments the semaphore to 1, allowing P2 to pass the `wait()`.

Q19. What is the purpose of initializing the semaphore to 0 in the S1/S2 synchronization example?

A.To ensure P1 executes before P2.
B.To ensure P2 blocks until P1 signals. ✅
C.To ensure both processes execute simultaneously.
D.To prevent both processes from executing.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The semaphore is initialized to 0 to ensure P2 blocks on its `wait(synch)` call. P1 will execute S1, then call `signal(synch)`, which increments the semaphore to 1. This allows P2 to proceed. The initialization to 0 enforces the required ordering: S1 must complete before S2.

Q20. What is the general purpose of using semaphores for synchronization?

A.To ensure processes execute in a specific order. ✅
B.To manage memory allocation.
C.To handle hardware interrupts.
D.To schedule processes for CPU execution.
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Semaphores are used to synchronize processes and ensure they execute in a specific order. They allow processes to coordinate their activities, such as ensuring one statement executes before another, or managing access to shared resources.

Q21. How does a semaphore with a value of 0 behave for a process executing `wait()`?

A.It allows the process to proceed.
B.It blocks the process. ✅
C.It increments the semaphore.
D.It sets the semaphore to 1.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a process executes `wait()` on a semaphore with value 0, the process blocks. This is because the condition for proceeding (semaphore value > 0) is not met. The process will remain blocked until the semaphore value becomes positive due to a `signal()` operation.

Q22. What is the main advantage of using counting semaphores for resource management?

A.They are faster than binary semaphores.
B.They allow multiple processes to access different instances of a resource concurrently. ✅
C.They are easier to implement.
D.They prevent all race conditions.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Counting semaphores allow multiple processes to access different instances of a resource concurrently. The semaphore value tracks the number of available resources, allowing processes to acquire and release them without conflicts, as long as the total number in use does not exceed the initial count.

Q23. What happens if a process calls `signal()` on a counting semaphore that is already at its maximum value?

A.The semaphore value overflows.
B.The semaphore value remains at the maximum. ✅
C.The semaphore value increments beyond the maximum.
D.The process blocks.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: While the semaphore definition allows incrementing to any value, in practice, the maximum is typically the initial number of resources. If a process calls `signal()` when all resources are already available, it indicates a programming error. Many implementations cap the value at the initial count or allow it to exceed, but this can lead to logical errors.

Q24. In the S1/S2 synchronization problem, what would happen if the semaphore were initialized to 1 instead of 0?

A.P2 would execute S2 before S1. ✅
B.P1 would block.
C.Both processes would execute correctly.
D.A deadlock would occur.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: If the semaphore were initialized to 1, P2's `wait(synch)` would succeed immediately (since synch > 0), and P2 could execute S2 before P1 executes S1. This violates the required ordering. Initializing to 0 is essential to make P2 wait until P1 signals.

Q25. Which type of semaphore is most suitable for managing a pool of database connections?

A.Binary semaphore.
B.Counting semaphore. ✅
C.Mutex lock.
D.Spinlock.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A counting semaphore is most suitable for managing a pool of database connections. The semaphore would be initialized to the number of connections in the pool. Each time a process needs a connection, it calls `wait()`; when it's done, it calls `signal()`. This ensures connections are not exceeded.

Q26. What is the value of a semaphore used for controlling access to 5 printers if all printers are in use?

A.0 ✅
B.1
C.5
D.-5
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: If all 5 printers are in use, the semaphore value would be 0. This indicates that no resources are available. Any process attempting to acquire a printer would block on the `wait()` operation until a printer is released and the semaphore is incremented back to a positive value.

Q27. What is the value of a semaphore used for controlling access to 5 printers if 3 printers are in use?

A.0
B.2 ✅
C.3
D.5
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: If 3 printers are in use, 2 printers are available. The semaphore value represents the number of available resources, so it would be 2. This allows up to 2 more processes to acquire a printer without blocking.

Q28. What is the primary purpose of using semaphores to ensure S2 executes after S1?

A.To prevent race conditions.
B.To enforce a specific execution order between two processes. ✅
C.To manage memory allocation.
D.To handle hardware interrupts.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The primary purpose is to enforce a specific execution order. By using a semaphore initialized to 0, P2 is forced to wait until P1 signals that S1 has completed, ensuring S2 is executed after S1. This is a classic synchronization problem.

Q29. In the S1/S2 synchronization problem, what code does P1 execute?

A.wait(synch); S1; signal(synch);
B.S1; signal(synch); ✅
C.signal(synch); S1;
D.S1; wait(synch);
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: P1 executes S1 followed by signal(synch). This ensures that S1 is executed before the semaphore is signaled. The signal operation then allows P2, which is waiting on the semaphore, to proceed and execute S2.

Q30. In the S1/S2 synchronization problem, what code does P2 execute?

A.S2; wait(synch);
B.wait(synch); S2; ✅
C.signal(synch); S2;
D.S2; signal(synch);
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: P2 executes wait(synch) followed by S2. The wait operation will block P2 until the semaphore is signaled by P1. Once P1 signals, P2 proceeds and executes S2. This ensures S2 is executed after S1.

Q31. What is the condition for a process executing `wait()` on a counting semaphore to proceed without blocking?

A.The semaphore value must be 0.
B.The semaphore value must be greater than 0. ✅
C.The semaphore value must be less than 0.
D.The semaphore value must be 1.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A process executing `wait()` on a counting semaphore proceeds without blocking only if the semaphore value is greater than 0. In this case, it decrements the value and continues. If the value is 0, the process blocks until the value becomes positive.

Q32. What is the effect of a `signal()` operation on a blocked process?

A.It immediately unblocks the process.
B.It increments the semaphore value, potentially allowing the blocked process to proceed. ✅
C.It blocks the process further.
D.It has no effect.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A `signal()` operation increments the semaphore value. If a process was blocked on the semaphore (i.e., the value was 0), the increment may make the value positive, allowing the blocked process to proceed. The `signal()` operation itself does not directly unblock a process; it just makes the resource available.

Q33. How does a binary semaphore differ from a counting semaphore in terms of initialization?

A.A binary semaphore is always initialized to 0.
B.A counting semaphore can be initialized to any non-negative integer. ✅
C.A binary semaphore can be initialized to any integer.
D.There is no difference.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A counting semaphore can be initialized to any non-negative integer value, representing the number of available resources. A binary semaphore is a special case initialized to either 0 or 1, with values restricted to these two. This difference in initialization reflects their different purposes.

Q34. Which type of semaphore would you use to ensure that a producer does not add data to a buffer when it is full?

A.Binary semaphore.
B.Counting semaphore. ✅
C.Both binary and counting semaphores.
D.Neither type.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A counting semaphore is often used to manage buffer capacity. The semaphore is initialized to the buffer size. The producer calls `wait()` before adding data (decrementing the count) and `signal()` after (incrementing it). If the buffer is full, the count is 0, and the producer blocks, preventing overflow.

Q35. What is the main purpose of the semaphore in the S1/S2 synchronization example?

A.To prevent race conditions.
B.To enforce an ordering constraint between two statements. ✅
C.To manage a shared resource.
D.To implement mutual exclusion.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The semaphore in the S1/S2 example is used to enforce an ordering constraint. The goal is specifically to ensure that S2 executes only after S1. The semaphore is not used for mutual exclusion or resource management but solely for sequencing the execution of statements.

Q36. If two processes share a semaphore initialized to 0 and both call `wait()` on it, what happens?

A.Both processes proceed.
B.Both processes block. ✅
C.One process proceeds, the other blocks.
D.An error occurs.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If the semaphore is initialized to 0 and both processes call `wait()`, the first process will decrement the value to -1 (in a theoretical sense) or block, and the second will also block. In a standard counting semaphore, the value is checked first; if it's 0, both would block, and the value might become negative (representing the number of waiting processes) depending on the implementation.

Q37. What is the primary advantage of using binary semaphores in systems without mutex locks?

A.They are faster.
B.They can provide mutual exclusion. ✅
C.They can be used for counting.
D.They are easier to implement.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In systems without mutex locks, binary semaphores can be used as a substitute to provide mutual exclusion. By initializing the semaphore to 1 and using `wait()` and `signal()` around critical sections, binary semaphores effectively act as mutex locks.

Q38. How does the `signal()` operation help prevent deadlock in resource management?

A.It releases resources, allowing waiting processes to proceed. ✅
B.It prevents processes from acquiring resources.
C.It kills deadlocked processes.
D.It has no effect on deadlock.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The `signal()` operation releases a resource by incrementing the semaphore count. This can unblock a waiting process that is trying to acquire the resource, allowing the system to make progress. However, improper use of semaphores can still lead to deadlock, so `signal()` alone is not a complete solution.

Q39. What is the role of a semaphore in a producer-consumer problem?

A.To manage the number of items in the buffer.
B.To manage access to the buffer for both producers and consumers.
C.To ensure producers and consumers do not access the buffer simultaneously.
D.All of the above. ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: In the producer-consumer problem, semaphores are used for multiple purposes. A counting semaphore tracks the number of items in the buffer (empty and full slots). A binary semaphore (or mutex) ensures mutual exclusion for accessing the buffer. This combination manages both the availability of items and the safe access to the shared buffer.

Q40. What happens to a process that calls `wait()` on a semaphore with a negative value?

A.It proceeds normally.
B.It blocks.
C.It decrements the value further and blocks. ✅
D.It raises an exception.
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: In a typical semaphore implementation, a negative value indicates the number of blocked processes. When a process calls `wait()` on a semaphore with a negative value, it blocks and the value is decremented further, representing that another process is waiting. The process will only proceed when a `signal()` increments the value back above 0.

Q41. Which synchronization tool is more suitable for managing multiple instances of a resource?

A.Mutex lock.
B.Binary semaphore.
C.Counting semaphore. ✅
D.Spinlock.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: A counting semaphore is specifically designed for managing multiple instances of a resource. Its value can range over an unrestricted domain, allowing it to represent the number of available resources. Mutex locks and binary semaphores are limited to two states and are more suitable for mutual exclusion.

Q42. How does the semaphore value change when a process acquires a resource in a counting semaphore?

A.It is incremented by 1.
B.It is decremented by 1. ✅
C.It is set to 0.
D.It is set to 1.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a process acquires a resource, the semaphore value is decremented by 1. This reflects that one fewer resource is available. If the value was n, after acquisition it becomes n-1. The process continues if the value before decrement was greater than 0.

Q43. How does the semaphore value change when a process releases a resource in a counting semaphore?

A.It is decremented by 1.
B.It is incremented by 1. ✅
C.It is set to 0.
D.It is set to 1.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a process releases a resource, the semaphore value is incremented by 1. This reflects that one more resource is available. If the value was n, after release it becomes n+1 (or capped at the maximum number of resources). This may unblock a waiting process.

Q44. What is the relationship between a binary semaphore and a mutex lock?

A.They are identical in functionality.
B.A binary semaphore can be used as a mutex lock. ✅
C.A mutex lock is more powerful than a binary semaphore.
D.They have no relationship.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A binary semaphore can be used as a mutex lock because both provide mutual exclusion. However, mutex locks often have additional features like ownership and priority inheritance, while binary semaphores are more basic. Despite these differences, a binary semaphore can effectively serve as a mutex lock.

Q45. What is the purpose of the `wait()` operation in the context of resource management?

A.To release a resource.
B.To acquire a resource. ✅
C.To create a new resource.
D.To delete a resource.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The `wait()` operation is used to acquire a resource. It decrements the semaphore count, indicating that a resource is now in use. If no resources are available, the process blocks until a resource is released.

Q46. What is the purpose of the `signal()` operation in the context of resource management?

A.To acquire a resource.
B.To release a resource. ✅
C.To create a new resource.
D.To delete a resource.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The `signal()` operation is used to release a resource. It increments the semaphore count, indicating that a resource is now available for other processes to use. This operation can unblock a process that was waiting for the resource.

Q47. What is the value of a semaphore after 3 `wait()` and 2 `signal()` operations, starting from 5?

A.3
B.4 ✅
C.5
D.6
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Starting from 5, 3 `wait()` operations decrement the value to 2 (5-3=2). Then, 2 `signal()` operations increment the value to 4 (2+2=4). The final value is 4, indicating that 4 resources are available.

Q48. What is the condition for a process to be blocked on a semaphore?

A.The semaphore value is greater than 0.
B.The semaphore value is less than or equal to 0. ✅
C.The semaphore value is 1.
D.The semaphore value is any positive integer.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A process blocks on a semaphore when the semaphore value is less than or equal to 0. This indicates that no resources are available or that the process must wait for a signal. The process will remain blocked until the semaphore value becomes positive due to a `signal()` operation.

Q49. What is the primary use of a semaphore initialized to 0?

A.To manage resources.
B.To enforce an ordering constraint. ✅
C.To provide mutual exclusion.
D.To count processes.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A semaphore initialized to 0 is typically used to enforce an ordering constraint between processes. A process that calls `wait()` on it will block until another process calls `signal()`, ensuring that the signaling process executes something before the waiting process proceeds.

Q50. How does the initialization value of a semaphore affect its behavior?

A.It determines the initial number of available resources. ✅
B.It determines the maximum number of processes.
C.It determines the scheduling policy.
D.It has no effect on behavior.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The initialization value of a semaphore determines the initial number of available resources. For a counting semaphore, it is set to the number of resources. For a binary semaphore used for mutual exclusion, it is set to 1. The initialization is critical for the correct behavior of the semaphore.

Q51. What is the maximum value of a counting semaphore?

A.It is always 1.
B.It is always 0.
C.It is unbounded. ✅
D.It is the number of processes.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A counting semaphore has an unrestricted domain, meaning it can be any non-negative integer. There is no fixed maximum value. However, in practice, the maximum is often limited by the number of resources it is managing or by the implementation's integer size.

Q52. What is the effect of a `signal()` operation on a semaphore with value -2?

A.The value becomes -1, and one blocked process is unblocked. ✅
B.The value becomes -3, and more processes block.
C.The value becomes 2, and all blocked processes are unblocked.
D.The value becomes 0, and no processes are unblocked.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: In a typical semaphore implementation, a negative value indicates the number of blocked processes. When `signal()` is called, the value is incremented. If the value becomes less than or equal to 0, it means at least one process is still blocked. If it becomes -1, one process has been unblocked, and the value reflects the remaining blocked processes.

Q53. What would happen if a process forgot to call `signal()` after releasing a resource?

A.Other processes would be able to acquire the resource anyway.
B.Other processes waiting for the resource would block indefinitely. ✅
C.The semaphore value would become negative.
D.The system would crash.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Forgetting to call `signal()` after releasing a resource is a serious programming error. The semaphore count would not be incremented, so waiting processes would never see the resource as available and would block indefinitely. This is a form of deadlock caused by a programming mistake.

Q54. What is the main difference between binary semaphores and mutex locks in practice?

A.Binary semaphores are faster.
B.Mutex locks often have ownership tracking, while binary semaphores do not. ✅
C.Binary semaphores are more powerful.
D.There is no practical difference.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: While binary semaphores can be used as mutex locks, there is a key difference: mutex locks typically enforce ownership. Only the process that acquired the mutex can release it. Binary semaphores do not have this ownership restriction, meaning any process can call `signal()` on the semaphore, potentially leading to logical errors.

Q55. What is the main purpose of the synchronization example with P1 and P2?

A.To demonstrate mutual exclusion.
B.To demonstrate ordering constraints between processes. ✅
C.To demonstrate resource management.
D.To demonstrate deadlock prevention.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The example with P1 and P2 is specifically designed to demonstrate ordering constraints. The goal is to ensure that S2 in P2 executes only after S1 in P1 has completed. This is a classic example of using semaphores for process synchronization, not mutual exclusion.

Q56. What is the significance of the `signal(synch)` statement in P1?

A.It tells P1 to wait.
B.It signals P2 that S1 has completed. ✅
C.It acquires the semaphore.
D.It releases the semaphore.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The `signal(synch)` statement in P1 is significant because it signals P2 that S1 has completed. This increments the semaphore from 0 to 1, allowing P2 to proceed past its `wait(synch)` call and execute S2. This is the key to enforcing the required ordering.

🔗 Related Topics (MCQs)