Consider the following savage-cook monitor version. 1. Consider the first versio
ID: 3914074 • Letter: C
Question
Consider the following savage-cook monitor version.
1. Consider the first version of the implementation in which we had only one signal in each method.
Given service methods: getServing(), putServings(), with local variables size = M and #servings = 0, and condition variables Food and NoFood.
GetServing(){
while (#servings == 0) {
signal(NoFood);
wait(Food);
}
#Servings--;
}
PutServing():
If(#servings != 0) wait(NoFood);
#servings = M;
signal(Food);
Give the execution sequence that shows deadlock or delay (depending on the fact that savage’s execution code is or is not a while(true) loop).
2. Do we need to have if (#servings != 0) wait(NoFood) in the Cook pseudo-code ? Or, since if a savage finds the pot empty it will signal the Cook anyway and wait(NoFood) only is enough. What will be the outcome of the above change? (what condition of Critical Section Problem might be violated?) Give the execution sequence that will show it.
3. The savage waits for Food, the cook waits for NoFood. a. Can we, instead of two condition variables, use only one? (let’s say: potStatus). Discuss. What will be the outcome of the change. 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
According to your necessity I have composed arrangement which satisfy every one of your prerequisites please tail it well ordered.
1. There will be a halt and deferral. On the off chance that there is nourishment simply serving is sufficient. No compelling reason to pause or cook all things considered. Here in the program given the capacity put serving must just serve the sustenance. In any case, rather than that there is a decision to get ready sustenance.
In the capacity take serving() if there is no nourishment there is no compelling reason to decrement the servings. So in this capacity the stop happens.
2. No there is no need of this announcement. Since if nourishment is there is no requirement for pausing. In the event that there is no sustenance then rather than hold up cook capacity ought to be worked out.
3. Truly we can utilize one capacity rather its enough. Since there is just a single pot. No it can be executed effectively.