Organize yourselves into groups of two or three students. Discuss the following problems in your group. Elect one person to be group scribe to type up your team's answers.
In these problems cooperating processes share the following:
const int BUFFER_SIZE; //This is the buffer size
typedef item …; // item is of some type or class….
item buffer[BUFFER_SIZE]; //array is of type item;
int in=0, out =0;
The variables in and out are initialized to 0. The shared buffer is basically
a “circular” array with integer “pointers” in and out
where in points to the next free position and out to the first full position
in the buffer. Elect one person to be group scribe to write up your group answers.
nextp and nextc are local variables in which items
to be produced or consumed are stored.
1. Bounded Buffer Problem
Producer process pseudo-code:
int nextp=0;
while (true)
{
//produce an item in nextp;
buffer[in]=nextp;
in=(in+1)%BUFFER_SIZE;
}
Consumer process pseudo-code:
int nextc=0;
while (true)
{
while(in==out); //do no-op;
nextc=buffer[out];
out=(out+1)%BUFFER_SIZE;
//consume next item in nextc
}
in==out;(in + 1) % BUFFER_SIZE
== out.BUFFER_SIZE items
in the buffer at the same time.2. Bounded Buffer with Counter Problem
int counter = 0; //Assume that the global counter is initialized to 0.
Producer process pseudo-code:
do
{
//produce an item in nextp;
while(counter==BUFFER_SIZE); //do no-op;
buffer[in]=nextp;
in=(in+1)%BUFFER_SIZE;
counter=counter+1;
}while (true);
Consumer process pseudo-code:
do
{
while(counter==0); //do no-op;
nextc=buffer[out];
out=(out+1)%BUFFER_SIZE;
counter=counter-1;
//consume the next item in nextc
}while (true);
Save your text file as yourlastnameT4.txt.