41 lines
1.1 KiB
Plaintext
41 lines
1.1 KiB
Plaintext
BACI System: C-- to PCODE Compiler in C, 11:30 1 Oct 2012
|
|
Source file: zad2.cm Mon Nov 26 16:53:03 2018
|
|
line pc
|
|
1 0 const int N = 5;
|
|
2 0 binarysem forks[N];
|
|
3 0 binarysem print_sem;
|
|
4 0 semaphore s;
|
|
5 0
|
|
6 0 void phil(int id)
|
|
7 0 {
|
|
8 0 int i;
|
|
9 0 for(i = 0; i < 1000; i++){
|
|
10 14 //wait(s);
|
|
11 14 wait(print_sem);
|
|
12 16 cout << "Jestem filozofem o numerze "<<id<<" i mysle" <<endl;
|
|
13 21 signal(print_sem);
|
|
14 23
|
|
15 23 wait(forks[id]);
|
|
16 27 wait(forks[(id+1)%N]);
|
|
17 35
|
|
18 35 wait(print_sem);
|
|
19 37 cout << "Jestem filozofem o numerze " <<id<<" i jem po raz " <<i+1<<endl;
|
|
20 46 signal(print_sem);
|
|
21 48
|
|
22 48 signal(forks[id]);
|
|
23 52 signal(forks[(id+1)%N]);
|
|
24 60 //signal(s);
|
|
25 60 }
|
|
26 61 }
|
|
27 62
|
|
28 62 main(){
|
|
29 63 int i;
|
|
30 63 for(i=0; i<N; i++)
|
|
31 77 initialsem(forks[i], 1);
|
|
32 83 initialsem(print_sem, 1);
|
|
33 86 //initialsem(s, 4);
|
|
34 86 cobegin{
|
|
35 87 phil(0); phil(1); phil(2); phil(3); phil(4);
|
|
36 107 }
|
|
37 108 }
|