diff --git a/Wykłady/prod-kons.cm b/Wykłady/prod-kons.cm new file mode 100644 index 0000000..f6465b8 --- /dev/null +++ b/Wykłady/prod-kons.cm @@ -0,0 +1,40 @@ +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(); + } +}