Pliki_SOP/Zadania_domowe/zajecia7/zad2.lst

57 lines
1.6 KiB
Plaintext
Raw Normal View History

2018-12-05 17:53:14 +01:00
BACI System: C-- to PCODE Compiler in C, 11:30 1 Oct 2012
Source file: zad2.cm Wed Dec 5 16:39:31 2018
line pc
1 0 const int N = 5;
2 0 binarysem forks[N];
3 0 binarysem print_sem;
4 0
5 0 void phil(int id)
6 0 {
7 0 int i;
8 0 for(i = 0; i < 1000; i++){
9 14 wait(print_sem);
10 16 cout << "Jestem filozofem o numerze "<<id<<" i mysle" <<endl;
11 21 signal(print_sem);
12 23
13 23 wait(forks[id]);
14 27 wait(forks[(id+1)%N]);
15 35
16 35 wait(print_sem);
17 37 cout << "Jestem filozofem o numerze " <<id<<" i jem po raz " <<i+1<<endl;
18 46 signal(print_sem);
19 48
20 48 signal(forks[id]);
21 52 signal(forks[(id+1)%N]);
22 60 }
23 61 }
24 62
25 62 void phil2(int id)
26 62 {
27 62 int i;
28 62 for(i=0; i<1000; i++){
29 76 wait(print_sem);
30 78 cout <<"Jestem filozofem o numerze "<<id<<" i mysle"<<endl;
31 83 signal(print_sem);
32 85
33 85 wait(forks[(id+1)%N]);
34 93 wait(forks[id]);
35 97
36 97 wait(print_sem);
37 99 cout<<"Jestem filozofem o numerze "<<id<<" i jem po raz "<<i+1<<endl;
38 108 signal(print_sem);
39 110
40 110 signal(forks[(id+1)%N]);
41 118 signal(forks[id]);
42 122 }
43 123 }
44 124
45 124 main(){
46 125 int i;
47 125 for(i=0; i<N; i++)
48 139 initialsem(forks[i], 1);
49 145 initialsem(print_sem, 1);
50 148 cobegin{
51 149 phil(0); phil2(1); phil(2); phil2(3); phil(4);
52 169 }
53 170 }