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 non-signaled state.
BoundedBuffer {
int BUFFER[MAX_SIZE];
int head, tail, size;
cond full, empty;
Enqueue (int v){
while ( size == MAX_SIZE)
full.wait();
BUFFER[tail]= v;
tail =(tail +1)% MAX_SIZE;
size++;
if (size==1) empty.signal();
}
Deque (int v){
while (size ==0) empty-wait();
int i = head;
head =(head +1)%MAX_SIZE;
size--;
if (size == MAX_SIZE -1)
full.signal;
return BUFFER[1]:
}
}
Now we can declare a BoundedBuffer monitor object bb by BoundedBufer bb;
(a) How many integer values can be stored in bb.BUFFER?
(b) How many threads can execute the bb.Enqueue 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!