Operating System dining savages problem with monitor implementation: The problem
ID: 3673826 • Letter: O
Question
Operating System dining savages problem with monitor implementation:
The problem of the dining savages (an allusion to the classic dining philosophers) is based on the arguably tasteless analogy of a number of members of a primitive culture, hereinafter called the "savages", sharing a meal from a single pot. The primary abstractions are the savages themselves, a cook, and the pot. The pot contains a certain number of servings of savage sustenance (the nature of which will be left to your imagination). Each of the savages can freely remove a serving from the pot so long as the pot is not empty. So before taking a serving, a savage must check to make sure the pot is not empty. In the case in which the pot is empty, the savage must wake up the cook to refill the pot, after which the feast continue. The savages, then, can eat only when the pot is not empty, and the cook can fill the pot only when the pot is empty.
Question:
The savage waits if there is EmptyPot, the cook waits for NotEmpty.
a. Can we, instead of two condition variables, use only one? (let’s say: potStatus). Discuss.
b. Is the assumption: If we have only one condition variable PotStatus, savage and cook cannot block at the same time on the condition variable correct?
Explanation / Answer
Yes we can use one status variable with condition , something like :
if (empty($potstatus)) {
echo '$potstatus is either 0 or empty and needs cook to fill the pot again ';
Savage wake up the cook to refill the pot
}
else {
echo ' Pot is not empty, savage continue with the feast '
Continue with the feast
That's Correct ,Condition variable will block only one at a time , either the Savage continue will the feast or cook will be busy to refill the pot .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.