From 440c533832ff43db2ef383ee95ddd427e77bbd2a Mon Sep 17 00:00:00 2001 From: s444505 Date: Sat, 2 Feb 2019 13:23:56 +0100 Subject: [PATCH] zadanko --- zadanie.cm | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 zadanie.cm diff --git a/zadanie.cm b/zadanie.cm new file mode 100644 index 0000000..8eff72e --- /dev/null +++ b/zadanie.cm @@ -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<