🎓 BookMCQ
← Back to 5. Process Synchronization

📝 Dining Philosophers Solution Using Monitors in Process synchronization (57 MCQs)

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

What is Dining Philosophers Solution Using Monitors in Process synchronization?

Definition:
The monitor solution to dining philosophers uses a state array state[i]{thinking,hungry,eating}state[i] \in \{thinking, hungry, eating\} and per-philosopher condition variables to safely grant forks only when neighbors are not eating.

Example:
Philosopher ii calls pickup(i)pickup(i), sets state[i]=hungrystate[i]=hungry, and tests canEat(i)canEat(i); if false, waits on self[i].wait()self[i].wait() until signaled by a neighbor's putdownputdown.

Reason:
This solution prevents deadlock by centralizing fork allocation logic and ensuring that state transitions are atomic, guaranteeing that no philosopher starves indefinitely under fair scheduling.

5
Easy
15
Medium
37
Hard

📝 All Dining Philosophers Solution Using Monitors in Process synchronization MCQs

Q1. What is the primary objective of the monitor solution to the dining-philosophers problem?

A.To allow philosophers to eat simultaneously
B.To provide a deadlock-free solution ✅
C.To increase the number of philosophers
D.To eliminate all chopsticks
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The monitor solution is specifically designed to provide a deadlock-free solution to the dining-philosophers problem. While the semaphore solution could lead to deadlock, the monitor-based approach uses condition variables and state checking to prevent deadlock from occurring.

Q2. What restriction does the monitor solution impose on philosophers picking up chopsticks?

A.A philosopher may pick up only one chopstick
B.A philosopher may pick up chopsticks only if both are available ✅
C.A philosopher may pick up any chopstick at any time
D.A philosopher must wait for all others to finish
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The monitor solution imposes the restriction that a philosopher may pick up her chopsticks only if both of them are available. This prevents the partial allocation scenario that leads to deadlock in the semaphore solution, where philosophers hold one chopstick while waiting for another.

Q3. How many states are defined for a philosopher in the monitor solution?

A.2
B.3 ✅
C.4
D.5
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The monitor solution defines three states for a philosopher: THINKING, HUNGRY, and EATING. These states represent the different phases a philosopher goes through: thinking (not hungry), hungry (wanting to eat), and eating (currently consuming food).

Q4. What is the purpose of the `state` array in the monitor solution?

A.To store philosopher names
B.To keep track of each philosopher's state (THINKING, HUNGRY, EATING) ✅
C.To store chopstick availability
D.To track eating time
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The `state` array keeps track of each philosopher's current state. Each philosopher can be in one of three states: THINKING, HUNGRY, or EATING. This state information is crucial for determining when a philosopher is allowed to pick up chopsticks and start eating.

Q5. What data type is used for the `state` array in the monitor solution?

A.int
B.boolean
C.enum ✅
D.string
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The `state` array uses an enum data type with three possible values: THINKING, HUNGRY, and EATING. This enum type clearly represents the distinct states a philosopher can be in, making the code more readable and type-safe.

Q6. What allows a philosopher to delay herself when hungry but unable to obtain chopsticks?

A.A semaphore
B.A mutex
C.A condition variable ✅
D.A timer
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A condition variable (`self[5]`) allows a philosopher to delay herself when hungry but unable to obtain the chopsticks she needs. The philosopher executes `self[i].wait()` to suspend herself until the condition variable is signaled by a neighbor who has finished eating.

Q7. What is the name of the monitor that controls the distribution of chopsticks?

A.DiningMonitor
B.PhilosopherMonitor
C.DiningPhilosophers ✅
D.ChopstickMonitor
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The monitor that controls the distribution of chopsticks is named `DiningPhilosophers`. This monitor encapsulates all the synchronization logic, including the state array, condition variables, and the functions `pickup()`, `putdown()`, and `test()`.

Q8. Which operation must a philosopher invoke before starting to eat?

A.putdown()
B.pickup() ✅
C.test()
D.wait()
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A philosopher must invoke the `pickup()` operation before starting to eat. This operation sets the philosopher's state to HUNGRY, calls `test()` to check if both chopsticks are available, and suspends the philosopher if the necessary chopsticks are not available.

Q9. Which operation must a philosopher invoke after finishing eating?

A.pickup()
B.putdown() ✅
C.test()
D.signal()
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A philosopher must invoke the `putdown()` operation after finishing eating. This operation sets the philosopher's state back to THINKING and calls `test()` on both neighbors to check if they can now start eating, potentially waking them up.

Q10. What is the sequence of monitor operations for philosopher i to eat?

A.putdown(i); eat; pickup(i)
B.pickup(i); eat; putdown(i) ✅
C.test(i); eat; test(i)
D.wait(i); eat; signal(i)
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The correct sequence is `pickup(i)` to acquire chopsticks, then eat, and finally `putdown(i)` to release chopsticks. This sequence ensures that the philosopher properly synchronizes with the monitor before and after eating, maintaining the deadlock-free property.

Q11. In the `test()` function, what condition must be true for philosopher i to be allowed to eat?

A.Only left neighbor is not eating
B.Only right neighbor is not eating
C.Both neighbors are not eating and philosopher i is HUNGRY ✅
D.Philosopher i is THINKING
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Philosopher i can set `state[i] = EATING` only if both neighbors are not eating and philosopher i is HUNGRY. The condition checks `(state[(i+4)%5] != EATING)` and `(state[(i+1)%5] != EATING)` and `(state[i] == HUNGRY)`.

Q12. What happens in the `pickup()` function if `test(i)` does not result in `state[i]` becoming EATING?

A.The philosopher continues to eat
B.The philosopher executes `self[i].wait()` ✅
C.The philosopher returns to THINKING
D.The philosopher exits the monitor
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: If `test(i)` does not result in `state[i]` becoming EATING, the philosopher executes `self[i].wait()`. This suspends the philosopher until a neighbor finishes eating and signals the condition variable, allowing the philosopher to retry and potentially acquire the chopsticks.

Q13. After a philosopher finishes eating and executes `putdown()`, which neighbors are tested?

A.Only the left neighbor
B.Only the right neighbor
C.Both the left and right neighbors ✅
D.No neighbors are tested
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: After a philosopher finishes eating and executes `putdown()`, both the left and right neighbors are tested. The function calls `test((i+4)%5)` for the left neighbor and `test((i+1)%5)` for the right neighbor to see if they can now start eating.

Q14. How many condition variables are declared in the monitor solution?

A.1
B.2
C.5 ✅
D.10
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The monitor solution declares 5 condition variables using `condition self[5]`. This allows each philosopher to have their own condition variable, so they can be individually suspended and woken up when their specific condition changes.

Q15. What is the purpose of the `test()` function in the monitor solution?

A.To test if a philosopher is thinking
B.To test if a philosopher can start eating and signal if possible ✅
C.To test if chopsticks are available
D.To test if a philosopher has finished eating
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The `test()` function checks if a philosopher can start eating. It verifies that the philosopher is HUNGRY and neither neighbor is EATING. If both conditions are met, it sets the state to EATING and signals the philosopher's condition variable to wake them up.

Q16. What is the initial state of all philosophers in the monitor solution?

A.EATING
B.HUNGRY
C.THINKING ✅
D.WAITING
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The initialization code sets all philosophers to the THINKING state. This represents the initial condition where no philosopher is hungry or eating, and all are in a neutral state before any synchronization operations occur.

Q17. What is the correct expression for the left neighbor of philosopher i in the 5-philosopher problem?

A.(i-1) % 5
B.(i+4) % 5 ✅
C.(i+5) % 5
D.(i-4) % 5
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The left neighbor of philosopher i is calculated as `(i+4) % 5`. Since modulo arithmetic is used, this effectively gives `(i-1) % 5` but handles the wrap-around correctly. For philosopher 0, the left neighbor is 4, and for philosopher 4, the left neighbor is 3.

Q18. What is the correct expression for the right neighbor of philosopher i in the 5-philosopher problem?

A.(i+1) % 5 ✅
B.(i-1) % 5
C.(i+4) % 5
D.(i+5) % 5
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The right neighbor of philosopher i is calculated as `(i+1) % 5`. This ensures that philosopher 4's right neighbor is philosopher 0, properly modeling the circular table arrangement. The modulo operation handles the wrap-around correctly.

Q19. What does the monitor solution guarantee regarding two neighbors eating simultaneously?

A.It allows two neighbors to eat together
B.It ensures no two neighbors are eating simultaneously ✅
C.It has no effect on neighbor eating
D.It depends on the philosopher
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The monitor solution ensures that no two neighbors are eating simultaneously. This is guaranteed by the `test()` function, which only allows a philosopher to eat if both neighbors are not eating. This prevents conflicts over shared chopsticks.

Q20. Even though the monitor solution is deadlock-free, what other problem may still occur?

A.Starvation ✅
B.Race condition
C.Data corruption
D.Memory leak
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Even though the monitor solution is deadlock-free, it is still possible for a philosopher to starve to death. Starvation can occur if a philosopher is repeatedly prevented from eating due to the scheduling of other philosophers, even though no deadlock exists.

Q21. In the `putdown()` function, what is the first operation performed?

A.test((i+4)%5)
B.test((i+1)%5)
C.state[i] = THINKING ✅
D.state[i] = HUNGRY
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The first operation in `putdown()` is setting `state[i] = THINKING`. This indicates that the philosopher has finished eating and is no longer hungry. After this, the function tests both neighbors to see if they can now start eating.

Q22. In the `test()` function, what happens when a philosopher is allowed to eat?

A.state[i] = HUNGRY
B.state[i] = THINKING
C.state[i] = EATING ✅
D.state[i] = WAITING
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: When a philosopher is allowed to eat, the `test()` function sets `state[i] = EATING` and then executes `self[i].signal()`. This signals the philosopher's condition variable, waking them up from any previous `wait()` call so they can proceed to eat.

Q23. What is the purpose of the `self[i].signal()` call in the `test()` function?

A.To suspend the philosopher
B.To wake up a waiting philosopher ✅
C.To check the philosopher's state
D.To set the philosopher to THINKING
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The `self[i].signal()` call in `test()` is used to wake up a waiting philosopher. When a philosopher was previously suspended because they couldn't get chopsticks, this signal wakes them up after the conditions become favorable (neighbors are done eating and both chopsticks are available).

Q24. In the `pickup()` function, after calling `test(i)`, why is there a check `if (state[i] != EATING)`?

A.To verify the philosopher is thinking
B.To check if the philosopher needs to wait ✅
C.To verify the philosopher has eaten
D.To check if the philosopher is hungry
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: After calling `test(i)`, the `if (state[i] != EATING)` check determines if the philosopher needs to wait. If `test(i)` was successful and the philosopher can eat, `state[i]` would be EATING. If not, the philosopher must execute `self[i].wait()` to be suspended.

Q25. What happens when a philosopher executes `self[i].wait()` in the `pickup()` function?

A.The philosopher continues eating
B.The philosopher is suspended until signaled ✅
C.The philosopher exits the monitor
D.The philosopher returns to THINKING
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When a philosopher executes `self[i].wait()`, the philosopher is suspended. The process will remain blocked until another philosopher (a neighbor) finishes eating and calls `test(i)` on this philosopher, which then executes `self[i].signal()` to wake them up.

Q26. In the `putdown()` function, why are both neighbors tested?

A.To ensure they are thinking
B.To allow neighbors to potentially start eating ✅
C.To check if they are hungry
D.To signal all philosophers
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Both neighbors are tested in `putdown()` because when a philosopher finishes eating, they release their chopsticks. This may allow either or both neighbors to now start eating. By testing both neighbors, the monitor ensures that any neighbor that is hungry and can now get both chopsticks is woken up.

Q27. What is the role of the `initialization code()` in the monitor?

A.To set all philosophers to EATING
B.To set all philosophers to HUNGRY
C.To set all philosophers to THINKING ✅
D.To initialize the condition variables
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The initialization code sets all philosophers to the THINKING state using a loop that iterates from 0 to 4 and assigns `state[i] = THINKING`. This establishes the initial condition where no philosopher is hungry or eating, and all are ready to start the thinking-eating cycle.

Q28. What is a potential issue with the monitor solution despite being deadlock-free?

A.It may cause data corruption
B.It may allow two neighbors to eat simultaneously
C.It may cause starvation ✅
D.It may cause race conditions
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The monitor solution is deadlock-free but may still cause starvation. A philosopher could starve if they are repeatedly prevented from eating by their neighbors, even though no deadlock occurs. This is a liveness issue that remains to be addressed.

Q29. How does the monitor solution prevent deadlock that occurs in the semaphore solution?

A.By using more semaphores
B.By allowing philosophers to pick up both chopsticks atomically ✅
C.By letting philosophers pick up any chopstick
D.By using a timer
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The monitor solution prevents deadlock by enforcing that a philosopher may pick up chopsticks only if both are available. This is checked atomically in the `test()` function. If both chopsticks are not available, the philosopher waits on a condition variable, preventing the partial allocation (holding one chopstick while waiting for another) that leads to deadlock.

Q30. Why is the condition variable `self[i]` specific to each philosopher?

A.To simplify the code
B.To allow individual philosophers to be suspended and woken up independently ✅
C.To reduce memory usage
D.To make the monitor faster
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Each philosopher has their own condition variable (`self[i]`) so they can be individually suspended and woken up. This is important because a philosopher should only be woken up when their specific condition (both neighbors not eating) becomes true, not when some other philosopher's condition changes.

Q31. What is the state of a philosopher immediately after they call `pickup()` but before `test(i)` is executed?

A.THINKING
B.HUNGRY ✅
C.EATING
D.WAITING
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Immediately after calling `pickup()`, the philosopher's state is set to HUNGRY (`state[i] = HUNGRY`). This indicates that the philosopher wants to eat and is ready to try to acquire chopsticks. The actual transition to EATING happens in `test()` if the conditions are met.

Q32. What is the state of a philosopher immediately after `test(i)` succeeds?

A.THINKING
B.HUNGRY
C.EATING ✅
D.WAITING
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: When `test(i)` succeeds, the philosopher's state is set to EATING (`state[i] = EATING`). This indicates that the philosopher has successfully acquired both chopsticks and can now proceed to eat. The `signal()` on the condition variable wakes the philosopher up from any previous wait.

Q33. How many elements does the `state` array contain?

A.2
B.3
C.4
D.5 ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The `state` array contains 5 elements, one for each philosopher. Each element stores the current state (THINKING, HUNGRY, or EATING) of that philosopher. The array is indexed from 0 to 4, representing the five philosophers seated around the table.

Q34. In the `test()` function, why is it necessary to check `state[i] == HUNGRY`?

A.To ensure the philosopher is thinking
B.To ensure the philosopher wants to eat ✅
C.To ensure the philosopher is eating
D.To ensure the philosopher is finished
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The `state[i] == HUNGRY` check ensures that the philosopher actually wants to eat. If a philosopher is not hungry (i.e., is THINKING), there is no need to try to give them chopsticks. This check prevents unnecessary signals to philosophers who are not interested in eating.

Q35. What happens in the `putdown()` function if `test((i+4)%5)` succeeds?

A.The left neighbor starts eating
B.The left neighbor is signaled ✅
C.The left neighbor's state becomes THINKING
D.The left neighbor is blocked
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If `test((i+4)%5)` succeeds, it means the left neighbor is hungry and both its neighbors are not eating. The `test()` function will set the neighbor's state to EATING and execute `self[left_neighbor].signal()`, waking up the left neighbor so they can start eating.

Q36. What is the significance of using modulo arithmetic in the neighbor calculations?

A.It simplifies the code
B.It handles the circular arrangement of philosophers ✅
C.It makes the code faster
D.It reduces memory usage
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Modulo arithmetic is used to handle the circular arrangement of philosophers. The expressions `(i+4)%5` and `(i+1)%5` correctly identify the left and right neighbors even when wrapping around the end of the array, ensuring that philosopher 0's left neighbor is philosopher 4 and philosopher 4's right neighbor is philosopher 0.

Q37. Which of the following is true about the `pickup()` function?

A.It always allows the philosopher to eat immediately
B.It may suspend the philosopher ✅
C.It never suspends the philosopher
D.It only works for even-numbered philosophers
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The `pickup()` function may suspend the philosopher if the necessary chopsticks are not available. After setting the state to HUNGRY and calling `test(i)`, if the state is still not EATING, the philosopher executes `self[i].wait()` and is suspended until a neighbor signals them.

Q38. What is the relationship between the `test()` function and the `signal()` operation?

A.`test()` never calls `signal()`
B.`test()` always calls `signal()`
C.`test()` calls `signal()` only when a philosopher can eat ✅
D.`test()` calls `signal()` only when a philosopher is thinking
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The `test()` function calls `self[i].signal()` only when a philosopher can eat (i.e., when the conditions for eating are met). This signal wakes up the philosopher if they were previously suspended in `pickup()`, allowing them to proceed to eat.

Q39. Why is the monitor solution considered deadlock-free?

A.Because it uses semaphores
B.Because it prevents circular wait by only allowing both chopsticks to be picked up atomically ✅
C.Because it uses a timer
D.Because it limits the number of philosophers
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The monitor solution is deadlock-free because it prevents the circular wait condition. By only allowing a philosopher to pick up both chopsticks atomically (checked in `test()`), it avoids the scenario where each philosopher holds one chopstick and waits for another. This breaks the circular dependency that causes deadlock.

Q40. What happens to a philosopher's state when they are suspended in `pickup()`?

A.It remains HUNGRY ✅
B.It changes to THINKING
C.It changes to EATING
D.It changes to WAITING
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: When a philosopher is suspended in `pickup()`, their state remains HUNGRY. They are hungry and waiting for chopsticks to become available. The state does not change to THINKING because they still want to eat, and it doesn't change to EATING because they haven't acquired the chopsticks yet.

Q41. What is the size of the `self` condition variable array?

A.2
B.3
C.4
D.5 ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The `self` condition variable array has 5 elements, one for each philosopher. This allows each philosopher to have their own condition variable for synchronization. The array is indexed from 0 to 4, corresponding to the five philosophers.

Q42. What is the purpose of the `pickup()` operation in the monitor solution?

A.To put down chopsticks
B.To test if a philosopher can eat
C.To allow a philosopher to acquire chopsticks and eat ✅
D.To set a philosopher to THINKING
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The `pickup()` operation allows a philosopher to acquire chopsticks and eat. It sets the philosopher's state to HUNGRY, tests if they can eat, and if not, suspends the philosopher. When the philosopher is woken up and the state is EATING, they can proceed to eat.

Q43. What is the purpose of the `putdown()` operation in the monitor solution?

A.To allow a philosopher to acquire chopsticks
B.To test if a philosopher can eat
C.To release chopsticks after eating and test neighbors ✅
D.To set a philosopher to HUNGRY
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The `putdown()` operation releases chopsticks after a philosopher has finished eating. It sets the philosopher's state to THINKING and tests both neighbors to see if they can now start eating. This allows other philosophers to acquire the released chopsticks.

Q44. What would happen if the `test()` function didn't check both neighbors?

A.The solution would still be deadlock-free
B.Starvation would be prevented
C.Two neighbors could eat simultaneously ✅
D.The code would run faster
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: If the `test()` function didn't check both neighbors, two neighbors could eat simultaneously. This would violate the fundamental constraint of the dining-philosophers problem, as two neighbors would be using the same chopstick at the same time, leading to conflicts and potential data corruption.

Q45. What is the effect of `self[i].signal()` in the `test()` function if philosopher i is not waiting?

A.It blocks the signaler
B.It has no effect ✅
C.It causes a deadlock
D.It signals the next philosopher
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If philosopher i is not waiting on `self[i]`, the `self[i].signal()` operation has no effect. This is consistent with the behavior of condition variables in monitors, where signaling a condition with no waiting processes does nothing. The signal is only meaningful if there is a process waiting to be woken up.

Q46. How does the monitor solution handle the case where a philosopher's neighbors are both eating?

A.The philosopher can still eat
B.The philosopher is suspended until a neighbor finishes ✅
C.The philosopher skips their turn
D.The philosopher changes to THINKING
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If both neighbors are eating, the philosopher is suspended in `pickup()` until at least one neighbor finishes eating. When a neighbor finishes and executes `putdown()`, they will call `test()` on this philosopher, which may allow them to eat if the conditions become favorable.

Q47. What is the key difference between the semaphore solution and the monitor solution to the dining-philosophers problem?

A.The semaphore solution is deadlock-free, the monitor is not
B.The monitor solution is deadlock-free, the semaphore is not ✅
C.Both are deadlock-free
D.Neither is deadlock-free
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The key difference is that the monitor solution is deadlock-free while the semaphore solution can lead to deadlock. The semaphore solution can deadlock when all philosophers grab their left chopstick simultaneously, while the monitor solution prevents this by only allowing both chopsticks to be picked up atomically after checking conditions.

Q48. What does the `test()` function do when it is called on a neighbor after a philosopher finishes eating?

A.Nothing
B.It may allow the neighbor to eat ✅
C.It forces the neighbor to wait
D.It changes the neighbor to THINKING
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When `test()` is called on a neighbor after a philosopher finishes eating, it may allow the neighbor to eat. The function checks if the neighbor is HUNGRY and if both of the neighbor's neighbors are not eating. If these conditions are met, the neighbor is allowed to eat and is signaled.

Q49. What is the state of philosopher 2's left neighbor in the 5-philosopher problem?

A.Philosopher 1 ✅
B.Philosopher 3
C.Philosopher 0
D.Philosopher 4
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Using the formula `(i+4)%5`, philosopher 2's left neighbor is `(2+4)%5 = 6%5 = 1`. So philosopher 1 is the left neighbor of philosopher 2. This correctly models the circular table where philosopher 2's left neighbor is philosopher 1.

Q50. What is the state of philosopher 4's right neighbor in the 5-philosopher problem?

A.Philosopher 3
B.Philosopher 0 ✅
C.Philosopher 2
D.Philosopher 1
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Using the formula `(i+1)%5`, philosopher 4's right neighbor is `(4+1)%5 = 5%5 = 0`. So philosopher 0 is the right neighbor of philosopher 4. This correctly models the circular table where philosopher 4's right neighbor is philosopher 0.

Q51. What is the name of the variable that allows a philosopher to delay themselves in the monitor solution?

A.self[i] ✅
B.wait[i]
C.signal[i]
D.delay[i]
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The variable that allows a philosopher to delay themselves is `self[i]`, which is a condition variable array. Each philosopher has their own condition variable (`self[0]` through `self[4]`) that they can wait on when they are hungry but unable to obtain chopsticks.

Q52. What would be the consequence if the `test()` function did not set `state[i] = EATING`?

A.The philosopher would never eat ✅
B.The philosopher would eat anyway
C.The philosopher would starve
D.The code would still work
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: If `test()` did not set `state[i] = EATING`, the philosopher would never eat. The `state[i]` must be set to EATING to indicate that the philosopher has acquired both chopsticks and can proceed to eat. Without this state change, the philosopher would remain HUNGRY and continue waiting indefinitely.

Q53. Why is the `test()` function called twice in the `putdown()` function?

A.To test the philosopher themselves
B.To test both neighbors ✅
C.To test all philosophers
D.To test the condition twice
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The `test()` function is called twice in `putdown()` to test both neighbors of the philosopher who just finished eating. Since the philosopher releases two chopsticks (one for each neighbor), both neighbors might now be able to eat. Testing both ensures that any hungry neighbor with both neighbors not eating can proceed.

Q54. What is the relationship between the `pickup()` and `putdown()` operations?

A.They are identical
B.They are complementary operations ✅
C.They are unrelated
D.One calls the other
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: `pickup()` and `putdown()` are complementary operations. `pickup()` is called before eating to acquire chopsticks, while `putdown()` is called after eating to release chopsticks. They work together to manage the philosopher's state and chopstick access, ensuring proper synchronization.

Q55. What would happen if a philosopher did not call `putdown()` after eating?

A.Other philosophers could not eat ✅
B.Starvation would occur
C.A deadlock would occur
D.The system would crash
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: If a philosopher did not call `putdown()` after eating, other philosophers could not eat because the chopsticks would never be released. The philosopher would remain in the EATING state, and neighbors waiting for chopsticks would never be signaled. This would effectively block the entire system.

Q56. What is the maximum number of philosophers that can be in the EATING state in this monitor solution?

A.1
B.2 ✅
C.3
D.4
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The maximum number of philosophers that can be in the EATING state is 2. This occurs when philosophers are not adjacent to each other (e.g., philosophers 0 and 2, or philosophers 1 and 3). The solution ensures no two neighbors are eating simultaneously, but non-adjacent philosophers can eat at the same time.

Q57. What is the primary benefit of using a monitor over semaphores for this solution?

A.The code runs faster
B.The monitor provides a more structured and safer approach to synchronization ✅
C.The monitor uses less memory
D.The monitor is simpler to implement
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The primary benefit is that the monitor provides a more structured and safer approach to synchronization. The monitor encapsulates the shared data and operations, making it harder to introduce errors like incorrect ordering of wait/signal operations. The implicit mutual exclusion and condition variables make the solution more robust.

🔗 Related Topics (MCQs)