This commit is contained in:
s444505 2019-02-02 13:23:56 +01:00
parent 2a16a2bab6
commit 440c533832

45
zadanie.cm Normal file
View File

@ -0,0 +1,45 @@
const int N=50;
int buffer[N];
int write=0;
int read=0;
binarysem sem;
void add1(){
int i;
for(i=1;i<=50;i++){
wait(sem);
buffer[write]=i;
write=(write+1)%N;
signal(sem);
}
}
void add2(){
int i=0;
for(i=51;i<=100;i++){
wait(sem);
buffer[write]=i;
write=(write+1)%N;
signal(sem);
}
}
void get(){
int item;
int i;
for(i=0;i<100;i++){
wait(sem);
item=buffer[read];
read=(read+1)%N;
cout<<item<<'\n';
signal(sem);
}
}
int main(){
initialsem(sem,1);
cobegin{
add1();add2();get();
}
}