Question: In the following, we implement a monitor called BoundedBuffer. Integer values can be stored in the BUFFER array via the Enqueue procedure, and the Deque
In the following, we implement a monitor called BoundedBuffer. Integer values can be stored in the BUFFER array via the Enqueue procedure, and the Deque procedure is used to remove integer values from BUFFER in FIFO order. We use condition variables full and empty to synchronize calls to Enqueue and Deque at boundary conditions. Initially, head, tail, and size are all set to zero, and both condition variables are set to nonsignaled state.
BoundedBuffer
int BUFFERMAXSIZE;
int head, tail, size;
cond full, empty;
Enqueue int v
while size MAXSIZE
full.wait;
BUFFERtail v;
tail tail MAXSIZE;
size;
if size empty.signal;
Deque int v
while size emptywait;
int i head;
head head MAXSIZE;
size;
if size MAXSIZE
full.signal;
return BUFFER:
Now we can declare a BoundedBuffer monitor object bb by BoundedBufer bb;
a How many integer values can be stored in bbBUFFER?
b How many threads can execute the bbEnqueue procedure concurrently?
c Can we replace the while statements with if statements? Why or why not?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
