Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

11 2015-16 ONLINE E4-1

1. P1 P2 (.
cobegin P1; P2; coend).

shared int a = 0; /* 0*/


P1 P2
local int b; /* P1*/ begin
begin a = a + 5;
b = a + 5; end
if (b == 5) then a = b + 5;
end

(.. a = b + 5)
( ). if
P1 - : b
5 ( -)
a a = b + 5 (
a -).
/ /; [1 ]
() a 10 15.[-0.5]
() a 5, 10 15. [+0.5]
() ()
4. [+0.5]
() ()
3. [-0.5]

2. (precedence graph)
P1, P2, P3, P4, P5 P6. o/
( cobegincoend)
/
; [1 ]

P1 P2

P3

P4

P5 P6

() [+0.25] () [+0.25]
semaphore s1, s2, s3, s4, s5; semaphore s1, s2, s3, s4;
s1 = s2 = s3 = s4 = s5 = 0; s1 = s2 = s3 = s4 = 0;
cobegin cobegin
begin P1; V(s1); end; begin P1; V(s1); end;
begin P2; V(s2); end; begin P2; V(s2); end;
begin P(s1); P3; V(s3); end; begin P(s1); P3; V(s3); end;
begin P(s3); P(s2); P4; V(s4); begin P(s3); P(s2); P4; V(s4);
V(s5); end; end;
begin P(s4); P5; end; begin P(s4); V(s4); P5; end;
begin P(s5); P6; end; begin P(s4); V(s4); P6; end;
coend coend

() [+0.25] () [+0.25]
semaphore s1, s2, s3; semaphore s1, s2, s3, s4;
s1 = s2 = s3 = 0; s1 = s3 = s4 = 0;
cobegin s2 = -1;
begin P1; P3; V(s1); end; cobegin
begin P2; V(s2); end; begin P1; V(s1); end;
begin P(s1); P(s2); P4; V(s3); begin P2; V(s2); end;
end; begin P(s1); P3; V(s2); end;
begin P(s3); V(s3); P5; end; begin P(s2); P4; V(s3); V(s4);
begin P(s3); V(s3); P6; end; end;
coend begin P(s3); P5; end;
begin P(s4); P6; end;
coend

3. , P1 P2:

P1 P2
repeat repeat
i:=1; j:=1;
count:=100; count:=200;
print(count+10); print(count+20);
repeat until j=0; repeat until i=0;
print(count+30); print(count+40);
i :=0; j :=0;
forever forever

. i, j, count
(shared) 0. /
/ / P1
P2 (
); [1 ]
() 110, 120, . [+0.5]
() 120, 220, . [-0.5]
() 210, 220, . [+0.5]
() . [-0.5]

4. P1, P2, P3, P4, P5, P6, P7:

begin
cobegin
begin
P1;
P3;
end;
P2;
coend;
P4;
end;
cobegin
P5;
begin
P6;
P7;
end;
coend;

/
; [1 ]

() [-0.33] () [-0.33]

() [+1] () [-0.33]
P1 P1
P2 P2

P3 P3

P4
P4

P5 P6 P7
P5 P6

P7

5. P1, P2, P3, P4, 0, 1, 3


7 . ( msec) T P1=5, TP2=7,
TP3=1 TP4=3. / /,
(context switch); [1 ]

() Shortest Job First (SJF) Shortest Remaining Time First


(SRTF) P4 . [-0.33]

() Round Robin 2 (RR(2)),


SRTF, 11 ()
P4. [-0.33]
() SJF ()
SRTF RR(2). [-0.33]
() SRTF ()
SJF RR(2). [+1]

6. /
/; [1 ]
() First Come First Serve (FCFS) Shortest Job First(SJF)
, ,
. [-0.33]
() Shortest Remaining Time First (SRTF)
SJF. [-0.33]
() Round Robin (RR)
. [+1]
() RR SJF
. [-0.33]

7. (paged segmentation) ()
4B, () 32 bits ()
() 48 bits
( ) 16 bits .
- (page table entry)
bits .
: 1 = 2^40 .
/ /; [1 ]
() 2G. [-0.5]
() ()
1T. [-0.5]
() 1048576. [+0.5]
() - 4 bytes. [+0.5]

8. (associative
registers), : () () o
5%, () () 20ms, ()
( / effective access time) 335ms.
(). [1 ]
() 325 ms [-0.33]
() 315 ms [-0.33]
() 310 ms [-0.33]
() 300 ms [+1]

9.
.
(0 3)
,
(0 7). , 1 , 2
,
3 , 4
, 5
6 bit R .

0, 1, 4 5 .


R

0 0 35 120 205 0
1 1 15 105 265 1
2 2 40 155 250 1
3 3 25 110 215 0

/ /; [1 ]
() (page fault) , FIFO
(First In First Out), 0 . [-0.5]
() (page fault) , LFU
(Least Frequently Used), 1 . [-0.5]
() (page fault) ,
(Second Chance), 3
. [+0.5]
() (page fault) , LRU
(Least Recently Used), 3
. [+0.5]

10.
(0 3). ,
x , (
) :

4720 900 1523 3120 50 2317 1800 3300 4900 2010

1 x-1
( 1
, 2
, 3
, 4
), / /
First In First Out (FIFO), Least Recently Used (LRU) ;
[1 ]



0 3 x-50 x-2
1 0 x-45 x-3
2 1 x-5 x-4
3 2 x-15 x-1

() FIFO 6
. [-0.33]
() . [-0.33]

() 5 (. 0 ),
. [+1]

() 4 (. 3 ),
FIFO LRU
. [-0.33]

&

1
.
, if P1
2 .
P1 P2
1.1: b = a + 5; 2.1: a = a + 5;
1.2: if (b == 5) then
1.3: a = b + 5;
() P1 P2
:
(1) 1.1; (b = 5) 1.2; ( b===5 TRUE) 1.3; (a = 10) 2.1; (a = 15)
(2) 1.1; (b = 5) 1.2; ( b===5 TRUE) 2.1; (a = 5) 1.3; (a = 10)
(3) 1.1; (b = 5) 2.1; (a = 5) 1.2; ( b===5 TRUE) 1.3; (a = 10)
(4) 2.1; (a = 5) 1.1; (b = 10) 1.2; ( b===5 FALSE)
1.3
, 4 a,
, 5, 10 15.
, , () () , ()
() .

2
( ())
.
( precedence relation
) . 5 (s1, s2, s3, s4, s5)
0. , ( )
P1 P2. P. :
P3 P(s1), P4 P(s3); P(s2)
( . P(s2); P(s3)), P5
P(s4) P6 P(s5).
P1 V(s1) P(s1)
P3 . P3
V(s3). P2 V(s2). (V(s3) V(s2))
P4 P (P(s3) P(s2)).
P4 V(s4) V(s5) (
. V(s5); V(s4)). V(s4) P5 (
P(s4)) . V(s5) P6 (
P(s5)) . , P5 P6
P4 ( ).
.
(binary semaphores), 0 1.
( ()) .
( 4
5 ). , P4
V ( V(S4)), P5 P6 P
7

V ( P(s4); V(s4)). P4 V(S4)


P5 P6 P(s4).
P5, V(s4) P6 P(s4).
P6, V(s4) P5
P(s4). , P5 P6 P4
( ). ,
0 1.
( ()) .

( 3 4 ). ,
P1 P3 ( P1
P3) P1; P3.
, 0 1.
( ()) .
... Webcast
( 'LS-webcast1-semaphores-definition.zip'). 4
(counting semaphores) . ,
Pi (i=3, 4, 5, 6) (. P3, P4, P5 P6)
( s1, s2, s3 s4, ) (di 1)
di Pi.
, : s1 = 0, s2 =
-1, s3 = 0 s4 = 0. ( P3, P4, P5 P6)
P . Pj (j=1, 2, 3, 4)
(. P1, P2, P3 P4) V
, (.
).

3

.

P1 P2
repeat repeat
1. i :=1; 7. j :=1;
2. count:=100; 8. count:=200;
3. print(count+10); 9. print(count+20);
4. repeat until j=0; 10. repeat until i=0;
5. print(count+30); 11. print(count+40);
6. i :=0; 12. j :=0;
forever forever

(
1 ).

1 7 . (busy waiting)
repeat until . 4 10 ( 3.2
- . ) .

,
:
) 1, 2 7, 8, 9, 10 3, 4.
220 210, .
) 7, 8 1, 2, 3, 4 9, 10.
110 120, .
) 1, 2 7, 8, 3, 4 9, 10.
210 220.
) 7, 8 1, 2, 9, 10 3, 4.
120 110.
( ) )), () ()
() (). To () ()
,
9 ( count 20), (
).

4
: P1 P3
begin end.
(P1 P3) P2, cobegin
coend . 4
1, 3 2. ( P4) P5, P6, P7
: P6, P7 ( )
P5.
, () P1 P3
. () P6, P7
.
() P1 P3 .
() P6, P7 .
() .

5
Gantt
:
1) SJF

P1 P3 P2 P4
0 5 6 13 16

2) SRTF

P1 P1 P3 1 P2 P4 P2
0 1 3 4 6 7 10 16

3) RR(2)

P1 P2 P1 P3 P2 P1 P4 P2 P4 P2
0 2 4 6 7 9 10 12 14 15 16

(): O SJF SRTF


. SJF
P4 ( 3
) P1, P2, P3
P4 . SRTF ,

, P4 (7)
.
SRTF
P3. , .
(): RR(2) 2msec,
. ,
2msec P1 2msec P2. 3 , P3
. P2
( 4), 1 2msec . 3
1msec, 7. P4.
P2, P1, P4, , ,
P2 . P1,
1msec P4 P2
. 11, Gantt,
P4.
SRTF
. , P1
0. 1 P2,
P1 P1 P2.
P1 4msec P2 7msec,
P1. 3 P3
. P3 1sec
, 4. P1 P2,
P1 ,
6. P2,
7 P4.
10. ,
P2. , 11 P2
.
(): () :
SJF: P1= 5 0 = 5, P2= 13 1 = 12, P3= 6 3 = 3, P4= 16 7 = 9
SJF = (P1+ P2+ P3+ P4)/4 = (5+12+3+9)/4 = 7,25 msec.

SRTF: P1= 6 0 = 6, P2= 16 1 = 15, P3= 4 3 = 1, P4= 10 7 = 3


SRTF = (P1+ P2+ P3+ P4)/4 = (6+15+1+3)/4 = 6,25 msec.

RR(2): P1= 10 0 = 10, P2= 16 1 = 15, P3= 7 3 = 4, P4= 15 7 = 8

10

RR(2) = (P1+ P2+ P3+P4)/4 = (10+15+4+8)/4 = 9,25 msec.


RR(2)
.

(): ():
SJF: P1= 5 5 = 0, P2= 12 7 = 5, P3= 3 1 = 2, P4= 9 3 = 6
SJF = (P1+ P2+ P3+ P4)/4 = (0+5+2+6)/4 = 3,25 msec.

SRTF: P1= 6 5 = 1, P2= 15 7 = 8, P3= 1 1 = 0, P4= 3 3 = 0


SRTF = (P1+ P2+ P3+ P4)/4 = (1+8+0+0)/4 = 2,25 msec.

RR(2): P1= 10 5 = 5, P2= 15 7 = 8, P3= 4 1 = 3, P4= 8 3 = 5


RR(2) = (P1+ P2+ P3+P4)/4 = (5+8+3+5)/4 = 5,25 msec.
, .

6
:
() FCFS - ,
, P1, P2, , Pn.
SJF - ,
.
P1, P2, , Pn
,
EP1< EP2< <EPn ( i
i)
. , ()
.
() . ,
, SRTF SJF.
2.7.4 .
() . RR
() ,
.
() SJF
,
.

11

() .
32 bits, 2^32 B = 2^(2+30) B = 2^2 GB = 4 GB ( 1
GB = 2^30 B).

() . ()
48 bits, ( )
2^48 = 2^(8+40) = 2^8 T = 256 T ( 1 TB = 2^40 B).

() . 32 bits
12 bits ( - -
4 = 4 x 2^10 = 2^2 x 2^10 = 2^12), (32-12) bits = 20
bits, 2^20 = 1048576 .

() . () 4 (=2^12B),
12 bits 20 bits (=3210) .
, (entry) 20 bits
6 bits . ,
26bits, 4 bytes.

8
( 4.25, . 137 - .
) :
= ( + ) * + ( + + ) * (1 - )
:
= (= 335ms )
= (= 20 ms )
= ( )
= " " (= 95% /
5%).
(
):
0,95 x (20+) + 0,05 x (20+2) = 335 =>
19 + 0,95 + 1 + 0,1 = 335 =>
20 + 1,05 = 335 =>
1,05 = 315 =>
= 300 ms
().

9
FIFO
(
),
(page fault - ),
,
( 4 ) 1 (

12

).
() .
1
(. 3 ) .
1, 1
( page fault),
..
3 ( ).
() .

FIFO, ( 4 ) 1.
bit '1' '0'
( FIFO) 3.
3 ( bit '1'), bit
'0' 3.
() .
, 0
3 , 5
.
0, 0
( page fault), ( )
,
3 ( ).
() .

10

1 = 1024Bytes.
0-1023 0, 1024-2047
1, 2048-3071 2, .
, x :
={4,0,1,3,0,2,1,3,4,1}

1) FIFO: FIF
. .

4 0 1 3 0 2 1 3 4 1


3 x-50 4 4 4 4 4 4 1 1 1 1
0 x-45 0 0 0 3 3 3 3 3 4 4
1 x-5 1 1 1 1 1 2 2 2 2 2
2 x-15 2 2 2 2 0 0 0 0 0 0

13

3 ( = x-50)
4, .
FIFO 6.
2) LRU: LRU .

.

.
bold .

4 0 1 3 0 2 1 3 4 1


3 x-2 3 3 1 1 1 1 1 1 1 1
0 x-3 0 0 0 0 0 0 0 0 4 4
1 x-4 4 4 4 4 4 2 2 2 2 2
2 x-1 2 2 2 3 3 3 3 3 3 3
X X X X X

LRU 5.
3) :
. .

4 0 1 3 0 2 1 3 4 1

3 3 3 3 3 3 3 3 3 3 3
0 0 0 0 0 0 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1
2 4 4 4 4 4 4 4 4 4 4

2.
:
() FIFO 6 ,
2 .
() ,
.

() , , 5 (.
0 ) (
) 0,1,3 4.

() , , 4
(. 3 ), FIFO
{4,3,1,2} LRU {1,0,4,3}.

14

15

You might also like