dodanie folderu zad dom

This commit is contained in:
Jakub Adamski 2018-12-05 17:53:14 +01:00
parent 9d9dbd31c5
commit 8be57ea953
12 changed files with 457 additions and 0 deletions

View File

@ -0,0 +1,29 @@
semaphore s;
semaphore t;
int liczba;
void kons(){
int i;
for(i=0; i<10; i=i+1){
wait(t);
cout << liczba << endl;
signal(s);
}
}
void prod(){
int i;
for(i=0; i<10; i=i+1){
wait(s);
liczba=i;
signal(t);
}
}
main(){
initialsem(s, 1);
initialsem(t, 0);
cobegin{
prod(); kons();
}
}

View File

@ -0,0 +1,32 @@
BACI System: C-- to PCODE Compiler in C, 11:30 1 Oct 2012
Source file: prod-cons.cm Tue Dec 4 15:01:25 2018
line pc
1 0 semaphore s;
2 0 semaphore t;
3 0 int liczba;
4 0
5 0 void kons(){
6 0 int i;
7 0 for(i=0; i<10; i=i+1){
8 14 wait(t);
9 16 cout << liczba << endl;
10 19 signal(s);
11 21 }
12 22 }
13 23
14 23 void prod(){
15 23 int i;
16 23 for(i=0; i<10; i=i+1){
17 37 wait(s);
18 39 liczba=i;
19 42 signal(t);
20 44 }
21 45 }
22 46
23 46 main(){
24 47 initialsem(s, 1);
25 50 initialsem(t, 0);
26 53 cobegin{
27 54 prod(); kons();
28 60 }
29 61 }

View File

@ -0,0 +1,112 @@
BACI System: C-- to PCODE Compiler in C, 11:30 1 Oct 2012
Source file: prod-cons.cm Tue Dec 4 15:01:25 2018
0 62 PCODE table
lc f x y
0 0 1 5
1 24 0 0
2 38 0 0
3 1 1 5
4 24 0 10
5 47 0 0
6 15 0 22
7 14 0 14
8 0 1 5
9 1 1 5
10 24 0 1
11 52 0 0
12 38 0 0
13 14 0 3
14 0 0 1
15 6 0 0
16 1 0 2
17 29 0 1
18 63 0 0
19 0 0 0
20 7 0 0
21 14 0 8
22 32 0 0
23 0 1 5
24 24 0 0
25 38 0 0
26 1 1 5
27 24 0 10
28 47 0 0
29 15 0 45
30 14 0 37
31 0 1 5
32 1 1 5
33 24 0 1
34 52 0 0
35 38 0 0
36 14 0 26
37 0 0 0
38 6 0 0
39 0 0 2
40 1 1 5
41 38 0 0
42 0 0 1
43 7 0 0
44 14 0 31
45 32 0 0
46 80 0 62
47 0 0 0
48 24 0 1
49 39 0 0
50 0 0 1
51 24 0 0
52 39 0 0
53 4 0 0
54 18 0 7
55 19 0 4
56 3 0 1
57 18 0 5
58 19 0 4
59 3 0 1
60 5 0 0
61 31 0 0
62 81 0 0
1 9 IDENTIFIER table
index identifier link obj type ref normal lev adr mon atomic
1 ++-outer-++ 0 7 0 0 1 0 62 0 0
2 s 1 1 5 0 1 0 0 0 0
3 t 2 1 5 0 1 0 1 0 0
4 liczba 3 1 1 0 1 0 2 0 0
5 kons 4 3 0 1 1 0 0 0 0
6 i 0 1 1 0 1 1 5 0 0
7 prod 5 3 0 2 1 0 23 0 0
8 i 0 1 1 0 1 1 5 0 0
9 main 7 6 0 3 1 0 46 0 0
0 3 BLOCK table
index last lastpar psize vsize
0 9 9 0 3
1 6 5 5 6
2 8 7 5 6
3 9 9 5 5
0 -1 ARRAY table
index inxtype eltyp elref low high elsize size
0 0 60 STRING table
0 0 Input File array
index parent file name
0 -1 prod-cons.cm
0 19 PCODE debugging information
lc findex flineno
0 0 7
14 0 8
16 0 9
19 0 10
21 0 11
22 0 12
23 0 16
37 0 17
39 0 18
42 0 19
44 0 20
45 0 21
46 0 23
47 0 24
50 0 25
53 0 26
54 0 27
60 0 28
61 0 29
62 0 -29

View File

@ -0,0 +1,26 @@
semaphore s;
semaphore t;
void a(){
cout << "Proces 1" <<endl;
signal(s);
}
void b(){
wait(s);
cout <<"Proces 2" <<endl;
signal(t);
}
void c(){
wait(t);
cout <<"Proces 3" <<endl;
}
main(){
initialsem(s, 0);
initialsem(t, 0);
cobegin{
a(); b(); c();
}
}

View File

@ -0,0 +1,29 @@
BACI System: C-- to PCODE Compiler in C, 11:30 1 Oct 2012
Source file: seq.cm Tue Dec 4 14:48:43 2018
line pc
1 0 semaphore s;
2 0 semaphore t;
3 0
4 0 void a(){
5 0 cout << "Proces 1" <<endl;
6 2 signal(s);
7 4 }
8 5
9 5 void b(){
10 5 wait(s);
11 7 cout <<"Proces 2" <<endl;
12 9 signal(t);
13 11 }
14 12
15 12 void c(){
16 12 wait(t);
17 14 cout <<"Proces 3" <<endl;
18 16 }
19 17
20 17 main(){
21 18 initialsem(s, 0);
22 21 initialsem(t, 0);
23 24 cobegin{
24 25 a(); b(); c();
25 34 }
26 35 }

Binary file not shown.

View File

@ -0,0 +1,59 @@
semaphore s2;
semaphore s;
semaphore t;
const int N = 5;
int buffer[N];
int write_pos = 0;
int read_pos = 0;
void queue_add(int item)
{
buffer[write_pos] = item;
write_pos = (write_pos + 1) % N;
}
int queue_get()
{
int item;
item = buffer[read_pos];
read_pos = (read_pos + 1) % N;
return item;
}
void prod1(int i, int n){
for(i; i <= n; i=i+1){
wait(s2);
queue_add(i);
signal(s);
}
signal(t);
}
void prod2(int i, int n){
wait(t);
for(i; i<=n; i=i+1){
wait(s2);
queue_add(i);
signal(s);
}
}
void kons(int n){
int i = 0;
int liczba;
for(i = 0; i < n; i = i+1){
wait(s);
liczba = queue_get();
signal(s2);
cout << "Pobralem" <<liczba<< endl;
}
}
main()
{
initialsem(s2, 5);
initialsem(s, 0);
initialsem(t, 0);
cobegin {
prod1(1, 25); prod2(101, 125); kons(50);
}
}

View File

@ -0,0 +1,61 @@
BACI System: C-- to PCODE Compiler in C, 11:30 1 Oct 2012
Source file: zad1.cm Wed Dec 5 14:22:03 2018
line pc
1 0 semaphore s2;
2 0 semaphore s;
3 0 semaphore t;
4 0 const int N = 5;
5 0 int buffer[N];
6 0 int write_pos = 0;
7 0 int read_pos = 0;
8 0 void queue_add(int item)
9 0 {
10 0 buffer[write_pos] = item;
11 5 write_pos = (write_pos + 1) % N;
12 12 }
13 13 int queue_get()
14 13 {
15 13 int item;
16 13 item = buffer[read_pos];
17 19 read_pos = (read_pos + 1) % N;
18 26 return item;
19 30 }
20 31
21 31 void prod1(int i, int n){
22 31 for(i; i <= n; i=i+1){
23 42 wait(s2);
24 44 queue_add(i);
25 48 signal(s);
26 50 }
27 51 signal(t);
28 53 }
29 54
30 54 void prod2(int i, int n){
31 54 wait(t);
32 56 for(i; i<=n; i=i+1){
33 67 wait(s2);
34 69 queue_add(i);
35 73 signal(s);
36 75 }
37 76 }
38 77
39 77 void kons(int n){
40 77 int i = 0;
41 80 int liczba;
42 80 for(i = 0; i < n; i = i+1){
43 94 wait(s);
44 96 liczba = queue_get();
45 101 signal(s2);
46 103 cout << "Pobralem" <<liczba<< endl;
47 107 }
48 108 }
49 109
50 109 main()
51 110 {
52 110 initialsem(s2, 5);
53 113 initialsem(s, 0);
54 116 initialsem(t, 0);
55 119 cobegin {
56 120 prod1(1, 25); prod2(101, 125); kons(50);
57 134 }
58 135 }

Binary file not shown.

View File

@ -0,0 +1,53 @@
const int N = 5;
binarysem forks[N];
binarysem print_sem;
void phil(int id)
{
int i;
for(i = 0; i < 1000; i++){
wait(print_sem);
cout << "Jestem filozofem o numerze "<<id<<" i mysle" <<endl;
signal(print_sem);
wait(forks[id]);
wait(forks[(id+1)%N]);
wait(print_sem);
cout << "Jestem filozofem o numerze " <<id<<" i jem po raz " <<i+1<<endl;
signal(print_sem);
signal(forks[id]);
signal(forks[(id+1)%N]);
}
}
void phil2(int id)
{
int i;
for(i=0; i<1000; i++){
wait(print_sem);
cout <<"Jestem filozofem o numerze "<<id<<" i mysle"<<endl;
signal(print_sem);
wait(forks[(id+1)%N]);
wait(forks[id]);
wait(print_sem);
cout<<"Jestem filozofem o numerze "<<id<<" i jem po raz "<<i+1<<endl;
signal(print_sem);
signal(forks[(id+1)%N]);
signal(forks[id]);
}
}
main(){
int i;
for(i=0; i<N; i++)
initialsem(forks[i], 1);
initialsem(print_sem, 1);
cobegin{
phil(0); phil2(1); phil(2); phil2(3); phil(4);
}
}

View File

@ -0,0 +1,56 @@
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 }

Binary file not shown.