forked from marcing/systemy-operacyjne-niestacjonarne-2018
41 lines
636 B
Plaintext
41 lines
636 B
Plaintext
monitor prod_kons {
|
|
int produkt;
|
|
int nowys;
|
|
condition nowy, uzyty;
|
|
void dodaj_element(int pr){
|
|
if(nowys==1) waitc(uzyty);
|
|
produkt=pr;
|
|
nowys=1;
|
|
signalc(nowy);
|
|
}
|
|
int pobierz_element(){
|
|
if(!nowys) waitc(nowy);
|
|
nowys=0;
|
|
signalc(uzyty);
|
|
return produkt;
|
|
}
|
|
init {
|
|
nowys = 0;
|
|
}
|
|
}
|
|
|
|
|
|
void producent(){
|
|
int i;
|
|
for(i=0;i<50;i++){
|
|
dodaj_element(i);
|
|
}
|
|
}
|
|
void konsument(){
|
|
int i;
|
|
for(i=0;i<50;i++){
|
|
cout << pobierz_element() << endl;;
|
|
}
|
|
}
|
|
|
|
main(){
|
|
cobegin{
|
|
producent(); konsument();
|
|
}
|
|
}
|