Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions