Computer Science 322 |
Lecture 08: Cooperating Processes
Date: Wednesday, February 20, 2008
The lecture assignment is postponed to Monday's lecture, to be due on Wednesday. There is no new lecture assignment due on Monday, February 25.
int buffer[n]; int in=0; int out=0;
while (1) { ... produce item; ... while (((in+1)%n) == out); /* busy wait */ buffer[in]=item; in=(in+1)%n; }
while (1) { while (in==out); /* busy wait */ item=buffer[out]; out=(out+1)%n; ... consume item; ... }
int buffer[n]; int in=0; int out=0; int counter=0;
while (1) { ... produce item; ... while (counter==n); /* busy wait */ buffer[in]=item; in=(in+1)%n; counter=counter+1; }
while (1) { while (counter==0); /* busy wait */ item=buffer[out]; out=(out+1)%n; counter=counter-1; ... consume item; ... }