49 lines
459 B
Plaintext
49 lines
459 B
Plaintext
monitor m{
|
|
condition c;
|
|
int ile;
|
|
int liczba1;
|
|
int liczba2;
|
|
|
|
void gen1(int n){
|
|
liczba1=n;
|
|
ile=ile+1;
|
|
if(ile==2) signalc(c);
|
|
}
|
|
|
|
void gen2(int n){
|
|
liczba2=n;
|
|
ile=ile+1;
|
|
if(ile==2) signalc(c);
|
|
}
|
|
|
|
int getSuma(){
|
|
if(ile < 2) waitc(c);
|
|
return liczba1+liczba2;
|
|
}
|
|
|
|
init{
|
|
liczba1=0;
|
|
liczba2=0;
|
|
ile=0;
|
|
}
|
|
}
|
|
|
|
|
|
void a(){
|
|
gen1(10);
|
|
}
|
|
|
|
void b(){
|
|
gen2(15);
|
|
}
|
|
|
|
void c(){
|
|
cout << getSuma() <<endl;
|
|
}
|
|
|
|
main(){
|
|
cobegin{
|
|
a(); b(); c();
|
|
}
|
|
}
|