Question
Given the following monitor as shown below: The methods add and sub are called in the following sequence: func 1 2 3 4 5 6
Given the following monitor as shown below: The methods add and sub are called in the following sequence:
func | 1 | 2 | 3 | 4 | 5 | 6 |
call | m.sub(); | m.sub (); | m.sub (); | m.add(); | m.sub(); | m.add(); |
Monitor m()
{
int val = 1, num = 1, buff = 2;
condition ad, sb;
add()
{
val += 2; //line 1
if(num == buff)
ad.wait(); //line 2
val--; //line 3
num++; //line 4
sb.signal(); //line 5
}
sub()
{
val--; //line 6
if (num == 0)
sb.wait(); //line 7
val += 2; //line 8
num--; //line 9
ad.signal(); //line 10
}
}
func | |||||||||||||||||||||||||||
line # | |||||||||||||||||||||||||||
int val | |||||||||||||||||||||||||||
int num |
Fill in the chart to show the exact SEQUENCE of executing the six function calls showing the variable values after executing each line of code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started