Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 11

11 4 (2005-06)

.
(. )
flag true.
while flag
false. . while
flag true . .

.

2 3,
flag true, while.
flag[1] true
flag[2] true (
). while
. .
.
(
)

S1 S2. S1
P(S1)
DVD V(S1) . S2
( ).
DVD S2
P(S2). ,
( V(S2)).

:
shared boolean beep ( false):
integer count ( 0): DVD
semaphore S1 ( 1):
semaphore S2 ( ):
DVD

P(S2);
P(S1);
DVD
count=count+1;
V(S1);

S2. S2
,
, .

S1, DVD, DVD 1
V(S1)
. , . ,
S2 0,
, P(S2).


while(1)
{
while (not beep) ; //
P(S1);

count=0;
for i=1 to M do V(S2);
V(S1);
}

beep. beep=true (
)
( P(S1)).
DVD ,
S1.
S2 ( V(S2))
.
V(S1).

2
3

1
() cobegin
1;
3;
5;
coend;
2;
4;

()
2 5,
.

() cobegin
1;
3;
coend;
cobegin
2;
5;
coend;
4;
()
. 5
1 3,
.

2

1,3 2.
6. 6
5 4.
:
cobegin
6;
5;
coend;
4;

3
. :

cobegin
cobegin
1;
3;
coend;
2;
5;
coend
4;

1
()
Lcs(m) Ucs(m)
: Lcs(m).

, Ucs(m).
m false.
:

Lcs(m);

Ucs(m);

Lcs(m), m true
.
Lcs(m), , m
true. Usc(m)
m=false
.

()
H Scs(c) : H c 1.
Scs(c)
x. x>0
. x<=0
Scs(c) c 1 (
Scs(c) c).
c 1. .
:

4
repeat
x=Scs(c);
if x<=0 then c=c+1;
until(x>0);

c=c+1;

Scs(c) :

function Scs( var c:integer):integer


begin
P(S);
tmp=c;
c=c-1;
V(S);
return tmp;
end

S
c .

m1, m2, m3
: m1=false, m2=true, m3=true.
:

cobegin
Process P1 Process P2 Process P3
repeat repeat repeat
begin begin begin
Lcs(m1); Lcs(m2); Lcs(m3);
write 1+2; write =3; write do it again ;
Ucs(m2); Ucs(m3); Ucs(m1);
end end end
until false; until false; until false;
coend
1 m1=false.
1 Ucs(m2) 2.
2 Ucs(m3)
3 Usc(m1)
1.

5
5

1
)



0 P1 < 512> - P1 - -
1 P2 <P1 85K> < 427> 1 2 - -
2 3 <1 85><2 95> 1 3 2 1
< 332>
3 4,5 < 85><2 95> 2 3,4,5 - -
< 332>
4 - <4 80>< 5> 2 3 4,5 -
<2 95><5 190>
< 142>
5 - <4 80>< 5> 2 3 4,5 -
<2 95><5 190>
< 142>
6 - <4 80>< 5> 4 3 5,2 -
<2 95><5 190>
< 142>
7 - <4 80>< 5> 4 3 5,2 -
<2 95><5 190>
< 142>
8 - <4 80>< 5> 4 3 5,2 -
<2 95><5 190>
< 142>
9 - <4 80>< 5> 5 3 2,4 -
<2 95><5 190>
< 142>
10 - <4 80>< 5> 5 3 2,4 -
<2 95><5 190>
< 142>
11 - <4 80>< 5> 5 3 2,4 -
<2 95><5 190>
< 142>
12 - <4 80>< 5> 2 3 4,5 -
<2 95><5 190>
< 142>
13 - <4 80>< 5> 2 3 4,5 -
<2 95><5 190>
< 142>
14 - <4 80>< 5> 2 3 4,5 -
<2 95><5 190>
< 142>
15 - <4 80>< 5> 4 3 5,2 4
<2 95><5 190>

6
< 142>
16 - < 85><2 95> 5 3 2 5
<5 190>< 142>
17 - < 85><2 95> 2 3 - 2
< 332>
18 - <3 350>< 162> 3 - - -
19 - <3 350>< 162> 3 - - -
20 - <3 350>< 162> 3 - - -
21 - <3 350>< 162> 3 - - -
22 - <3 350>< 162> 3 - - -



0 P1 < 512> - P1 - -
1 P2 <P1 85K> < 427> 1 2 - -
2 3 <1 85><2 95> 1 3 2 1
< 332>
3 4,5 <2 95><3 350> 2 4,5 3 -
< 67>
4 - <2 95><3 350> 2 4,5 3 -
< 67>
5 - <2 95><3 350> 2 4,5 3 -
< 67>
6 - <2 95><3 350> 3 4,5 2 -
< 67>
7 - <2 95><3 350> 3 4,5 2 -
< 67>
8 - <2 95><3 350> 3 4,5 2 -
< 67>
9 - <2 95><3 350> 2 4,5 3 -
< 67>
10 - <2 95><3 350> 2 4,5 3 -
< 67>
11 - <2 95><3 350> 2 4,5 3 -
< 67>
12 - <2 95><3 350> 3 4,5 2 -
< 67>
13 - <2 95><3 350> 3 4,5 2 3
< 67>
14 - <2 95><4 80> 2 - 4,5 2
<5 190>< 147>
15 - <4 80><5 190> 4 - 5 -
< 242>
16 - <4 80><5 190> 4 - 5 -
< 242>
17 - <4 80><5 190> 4 - 5 -

7
< 242>
18 - <4 80><5 190> 5 - 4 -
< 242>
19 - <4 80><5 190> 5 - 4 -
< 242>
20 - <4 80><5 190> 5 - 4 -
< 242>
21 - <4 80><5 190> 4 - 5 4
< 242>
22 - <5 190>< 322> 5 - - 5

) 3
4 5.
85 332 4,5 80 190
. best-fit 4 85 5
332. first-fit ,
. worst-fit 4 332
5. . .

)
,
.
( )
.
.

.
.

.
.
.

8
6



2350 2 350 1050 1400
0055 0 055 0 0055
1125 1 125 450 0575
1036 1 036 800 0836
4005 4 005 .

3305 3 305 1500 .

0021 0 021 650 0671

2
16 bits . 4
12 .

(i) : 0001110011001101

0001 110011001101.
1 7=111 2.
111110011001101=7CCD16.
15 bits ( 32=215).

(ii) 0000110011000000
: 0000
: 110011000000
0 4=1002.
100110011000000=4CC016.

(iii) : 0011010101010101
: 0011
: 010101010101
3 0.
000010101010101=055516.

(iv) : 0010110111111111
: 0010
: 110111111111
3 (invalid)
.

9
3

)
.
,
0 .

.
,
.

) ( )
.
.

(i) Round Robin 2. 2


.


0-2
2-4
4-5 1
5-7
7-9
9-12

(ii) Shortest Job First- preemptive. .



.


0-2
2-4
4-5
5-7
7-12

(iii) Shortest Job First non preemptive


0-7
7-8
8-12

10
2

(i) Round Robin 2.



: 12-0=12
: 9-2=7
: 5-4=1
=(12+7+1)/3=20/3=6,66


: 12-0-7=5
: 9-2-4=3
: 5-4-1=0
=(5+3+0)/3=8/3=2,66

(ii) Shortest Job First- preemptive



: 12-0=12
: 7-2=5
: 5-4=1
=(12+5+1)/3=18/3=6


: 12-0-7=5
: 7-2-4=1
: 5-4-1=0
=(5+1+0)/3=6/3=2

(iii) Shortest Job First- non preemptive



: 7-0=7
: 12-2=10
: 8-4=4
=(7+10+4)/3=21/3=7


: 7-0-7=0
: 12-2-4=6
: 8-4-1=3
=(0+6+3)/3=9/3=3

11

You might also like