Date post: | 03-Jun-2018 |
Category: |
Documents |
Upload: | manucian-reds |
View: | 225 times |
Download: | 0 times |
8/12/2019 Scheduling Deadlock
1/153
C 5: P S
8/12/2019 Scheduling Deadlock
2/153
C 5: P
S
B
T CS P P S S H
S C P S
M S E A A
8/6/2013 2OS Concepts 053006 -Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
3/153
O T ,
T
T
T
8/6/2013 3OS Concepts 053006 -Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
4/153
B P
M ,
C
I :S . W
counter . I, counter 0. I .
8/6/2013 4OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
5/153
Pwhile (true) {
/* produce an item in next produced */
while (counter == BUFFER_SIZE) ;
/* do nothing */
buffer in = next roduced_
in = (in + 1) % BUFFER_SIZE;
counter++;
}
8/6/2013 5OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
6/153
Cwhile (true) {
while (counter == 0); /* do nothing */
next_consumed = buffer[out];
= _
counter--;
/* consume the item in next consumed */
}
8/6/2013 6OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
7/153
R C counter++
register1 = counterregister1 = register1 + 1counter = register1
counter--
register2 = counter -
counter = register2 C = 5:
S0: register1 = counter 1 = 5S1: register1 = register1 + 1 1 = 6S2: register2 = counter 2 = 5S3: register2 = register2 1 2 = 4S4: counter = register1 = 6 S5: counter = register2 = 4
8/6/2013 7OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
8/153
C S P C , ,
E P , , , W ,
E , ,
8/6/2013 8OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
9/153
C S
G
8/6/2013 9OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
10/153
S CS
P1. I ,
2. I ,
3. A A
N
T , , CPU
E
8/6/2013 10OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
11/153
P
S G
T
A load store ; ,
T : int turn; Boolean flag[2]
T turn
T flag . flag[i] = true Pi !
8/6/2013 11OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
12/153
A P Pdo {
flag[i] = true;turn = j;
while (flag[j] && turn == j);
flag[i] = false;remainder section
} while (true);
P 1. M
2. P
3. B
8/6/2013 12OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
13/153
S H M
A P
U
C G O
M
= E O
8/6/2013 13OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
14/153
do {
acquire lock
critical section
release lock
S C P U L
remainder section} while (TRUE);
8/6/2013 14OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
15/153
I
D:
*_ _
{boolean rv = *target;
*target = TRUE;
return rv:
}
8/6/2013 15OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
16/153
S ()
S , FALSE
S:
do {
while (test_and_set(&lock))
; /* do nothing *//* critical section */
lock = false;
/* remainder section */
} while (true);
8/6/2013 16
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
17/153
I
D:
, , _
int temp = *value;if (*value == expected)
*value = new_value;
return temp;
}
8/6/2013 17
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
18/153
S
S B FALSE;
E B S:
do {while (compare_and_swap(&lock, 0, 1) != 0)
; /* do nothing */
/* critical section */
lock = 0;
/* remainder section */
} while (true);
8/6/2013 18
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
19/153
B M E
do {
waiting[i] = true;
key = true;while (waiting[i] && key)
key = test_and_set(&lock);
waiting[i] = false;
/* critical section */
j = (i + 1) % n;
while ((j != i) && !waiting[j])
j = (j + 1) % n;
if (j == i)
lock = false;
else
waiting[j] = false;
/* remainder section */
} while (true);
8/6/2013 19
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
20/153
M L
P
OS
S P acquire() release()
B
U
B
T
8/6/2013 20
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
21/153
() ()
acquire() {
while (!available)
; /* busy wait */available = false;;
}
release() {
available = true;
8/6/2013 21
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
}
do {
acquire lock
critical section
release lock
remainder section
} while (true);
8/12/2019 Scheduling Deadlock
22/153
S
S
S
T : wait() signal() O P() V()
L
C ()
wa t S
while (S
8/12/2019 Scheduling Deadlock
23/153
S U
0 1
T
C
C
C
P1:S1;
signal(synch);
P2:
wait(synch);
S2;
8/6/2013 23
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
24/153
S I
M wait() signal()
T,
B L
N
8/6/2013 24
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
25/153
S I
B
W
E : ( )
T :
8/6/2013 25
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
26/153
S I
B (C.)
typedef struct{
int value;
struct process *list;} semaphore;
wait(semaphore *S) {
S->value--;
if (S->value < 0) { -
block();}
}
signal(semaphore *S) {
S->value++;
if (S->value list;
wakeup(P);
}
}
8/6/2013 26
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
27/153
D S
L S Q 10 1
wait(S); wait(Q);
wait(Q); wait(S);. .
signal(S); signal(Q);
signal(Q); signal(S);
A
S S
8/6/2013 27
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
28/153
0 1
wait(S); wait(Q);wait(Q); wait(S);
signal(S); signal(Q);signal(Q); signal(S);
8/6/2013
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
28
8/12/2019 Scheduling Deadlock
29/153
C P
S
C
R W P
DP P
8/6/2013 29
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
30/153
BB P
,
Smutex 1
S full 0
S empty
8/6/2013 30
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
31/153
B B P (C.)
T
do {...
/* produce an item in next_produced */
...
wait(mutex);...
/* add next produced to the buffer */
...
signal(mutex);
signal(full);
} while (true);
8/6/2013 31
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
32/153
B B P (C.)
T
do {
wait(full);
wait(mutex);
...
_
...signal(mutex);
signal(empty);
...
/* consume the item in next consumed */
...
} while (true);
8/6/2013 32
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
33/153
RW P
A R ;
W
P O
S
S D
D S rw_mutex 1 Smutex 1 I read_count 0
8/6/2013 33
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
34/153
RW P (C.)
T
do {wait(rw_mutex);
...* *
...
signal(rw_mutex);
} while (true);
8/6/2013 34
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
35/153
RW P (C.)
T
do {
wait(mutex);read count++;if (read_count == 1)
wait(rw_mutex);
signal(mutex);
...
...
wait(mutex);read count--;if (read_count == 0)
signal(rw_mutex);
signal(mutex);
} while (true);
8/6/2013 35
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
R W P
8/12/2019 Scheduling Deadlock
36/153
RW P
V
,
B
P
8/6/2013 36
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
37/153
DP P
8/6/2013 37
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
38/153
DP P
P
D , 2 ( )
N , I 5
S
B ( ) S 5 1
8/6/2013 38
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
D P P
8/12/2019 Scheduling Deadlock
39/153
DP P
A T P:
do {wait (chopstick[i] );wait (chopStick[ (i + 1) % 5] );
// eat
signal (chopstick[i] );signal (chopstick[ (i + 1) % 5] );
// think
} while (TRUE);
W ?
8/6/2013 39
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
40/153
P S
I :
() . ()
() ()
O () () ( )
D
8/6/2013 40
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
41/153
M
A
,
O B
monitor monitor-name
// shared variable declarationsprocedure P1 () { . }
procedure Pn () {}
Initialization code () { }}
}
8/6/2013 41
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
42/153
S M
8/6/2013 42
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
43/153
C V
condition x, y;
T :x.wait()
x.signal()
x.signal() ( ) x.wait()
I x.wait() ,
8/6/2013 43
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
M C
8/12/2019 Scheduling Deadlock
44/153
M C
V
8/6/2013 44
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
45/153
C V C
I P x.signal(), Q x.wait() , ?
I Q , P
O
Q P
B
M C P P , Q
I M, C#, J
8/6/2013 45
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
46/153
S D P
monitor DiningPhilosophers{enum { THINKING; HUNGRY, EATING) state [5] ;
condition self [5];
void pickup (int i) {state[i] = HUNGRY;test(i);if (state[i] != EATING) self [i].wait;
}
void putdown (int i) {state[i] = THINKING;
// test left and right neighborstest((i + 4) % 5);
test((i + 1) % 5);}
8/6/2013 46
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S D P
8/12/2019 Scheduling Deadlock
47/153
S D P
(C.)
void test (int i) {
if ( (state[(i + 4) % 5] != EATING) &&(state[i] == HUNGRY) &&(state[(i + 1) % 5] != EATING) ) {
state[i] = EATING ;se .s gna ;
}}
initialization_code() {for (int i = 0; i < 5; i++)
state[i] = THINKING;}
}
8/6/2013 47
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S l i Di i Phil h (C )
8/12/2019 Scheduling Deadlock
48/153
E pickup() putdown() :
DiningPhilosophers.pickup(i);
EAT
Solution to Dining Philosophers (Cont.)
DiningPhilosophers.putdown(i);
N ,
8/6/2013 48
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
49/153
M I U S
V
semaphore mutex; // (initially = 1)semaphore next; // (initially = 0)
int next_count = 0; E
wait(mutex);
body of F;
if (next_count > 0)signal(next)
elsesignal(mutex);
M
8/6/2013 49
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
50/153
M I C V
F , :
semaphore x_sem; // (initially = 0)
int x_count = 0; T . :
x_count++;if (next_count > 0)
signal(next);else
signal(mutex);wait(x_sem);
x_count--;
8/6/2013 50
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
M I (C )
8/12/2019 Scheduling Deadlock
51/153
M I (C.)
T x.signal :
if (x_count > 0) {
next_count++;
signal(x_sem);
wait(next);
next_count--;
}
8/6/2013 51
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
R P
8/12/2019 Scheduling Deadlock
52/153
M I ,
.() , ?
.()W
P ( )
8/6/2013 52
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
A M A S
8/12/2019 Scheduling Deadlock
53/153
Rmonitor ResourceAllocator
{
boolean busy;condition x;
void acquire(int time) {
if (busy)
x.wait(time);
busy = TRUE;
}void release() {
busy = FALSE;
x.signal();
}
initialization code() {
busy = FALSE;}
}
8/6/2013 53
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
A T
8/12/2019 Scheduling Deadlock
54/153
A T
S M L R
C C A T
8/6/2013 54
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S M
8/12/2019 Scheduling Deadlock
55/153
S M
A , ,
R C
H T T ( ) ( )
A
8/6/2013 55
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
T S M
8/12/2019 Scheduling Deadlock
56/153
T S M
V
E: ,
N I
E:
S I
N , RAID
Goal is to assure transaction atomicity where failures cause loss of information on volatile storage
8/6/2013 56
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
L B R
8/12/2019 Scheduling Deadlock
57/153
LB R
R
M L ,
, T
D O
N
T
T L
8/6/2013 57
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
L B R A
8/12/2019 Scheduling Deadlock
58/153
LB R A
U ,
() T() T
U(T) (T) M
I ,
I , () I , ()
8/6/2013 58
OS Concepts 053006 -
Synchronization, Deadlock andScheduling
8/12/2019 Scheduling Deadlock
59/153
C T
8/12/2019 Scheduling Deadlock
60/153
C T
M
C
I,
8/6/2013 60OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S
8/12/2019 Scheduling Deadlock
61/153
S
C A B
C T T0 T1 E T0, T1
E
A
F N , N!
8/6/2013 61OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S 1: T T
8/12/2019 Scheduling Deadlock
62/153
S 1: T0 T1
8/6/2013 62OS Concepts 053006 -
Synchronization, Deadlock andScheduling
N S
8/12/2019 Scheduling Deadlock
63/153
N S
R
C S, O, O ,
I O, O
& O O T S OO S
I S S S
8/6/2013 63OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S 2: C S S
8/12/2019 Scheduling Deadlock
64/153
S 2: C S S
8/6/2013 64OS Concepts 053006 -
Synchronization, Deadlock andScheduling
L P
8/12/2019 Scheduling Deadlock
65/153
L P
E F
L T (S) Q, T Q
Q
T (X) Q, T
Q R Q I ,
S
8/6/2013 65OS Concepts 053006 -
Synchronization, Deadlock andScheduling
T L P
8/12/2019 Scheduling Deadlock
66/153
T L P
G
E
G
S
D
8/6/2013 66OS Concepts 053006 -
Synchronization, Deadlock andScheduling
T P
8/12/2019 Scheduling Deadlock
67/153
T P
S
T T TS(T) T
T T < T T T TTS
T
I TS(T) < TS(T), T T
8/6/2013 67OS Concepts 053006 -
Synchronization, Deadlock andScheduling
T P I
8/12/2019 Scheduling Deadlock
68/153
D Q W(Q)
(Q) R(Q) (Q)U (Q) (Q)
S T ()I TS(T) < W(Q), T Q
T I TS(T) W(Q) , R(Q) (R(Q), TS(T))
8/6/2013 68OS Concepts 053006 -
Synchronization, Deadlock andScheduling
T P
8/12/2019 Scheduling Deadlock
69/153
S T (Q)I TS(T) < R(Q), Q T
T , T
I TS(T) < W(Q), T Q
T O,
A T
A
8/6/2013 69OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S P U T P
8/12/2019 Scheduling Deadlock
70/153
8/6/2013 70OS Concepts 053006 -
Synchronization, Deadlock andScheduling
E C 5
8/12/2019 Scheduling Deadlock
71/153
8/6/2013 71OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
8/12/2019 Scheduling Deadlock
72/153
C 6: CPU S
8/6/2013OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
72
C 6: CPU S
8/12/2019 Scheduling Deadlock
73/153
B C
S C S A
MP S
RT CPU S
O S E A E
8/6/2013 73OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
O
8/12/2019 Scheduling Deadlock
74/153
T CPU ,
T CPU
T CPU
T
8/6/2013 74OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
B C
8/12/2019 Scheduling Deadlock
75/153
M CPU
CPUI/O B C P
I/O
/
CPU
8/6/2013 75OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
H CPU T
8/12/2019 Scheduling Deadlock
76/153
8/6/2013 76OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
CPU S
8/12/2019 Scheduling Deadlock
77/153
, CPU
Q CPU :
1. S
.
3. S
4. T
S 1 4
A C
C
C OS
8/6/2013 77OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
D
8/12/2019 Scheduling Deadlock
78/153
D CPU ;
:
8/6/2013 78OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
S C
8/12/2019 Scheduling Deadlock
79/153
CPU
#
, ( )
8/6/2013 79OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
S A O C
8/12/2019 Scheduling Deadlock
80/153
M CPU
M M
M M
8/6/2013 80OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
FC, FS (FCFS) S
8/12/2019 Scheduling Deadlock
81/153
P B T1 24
2 33 3 S : 1, 2, 3
W 1 = 0; 2 = 24; 3 = 27 A : (0 + 24 + 27)/3 = 17
P1 P2 P3
24 27 300
8/6/2013 81OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
FCFS S (C.)
8/12/2019 Scheduling Deadlock
82/153
S :
2, 3, 1 T G :
P1P3P2
W 1 6 2= 0 3 3 A : (6 + 0 + 3)/3 = 3 M
C CPU I/O
63 300
8/6/2013 82OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
SJF (SJF)
8/12/2019 Scheduling Deadlock
83/153
S A
CPU U
SJF T CPU
C
8/6/2013 83OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
E SJF
8/12/2019 Scheduling Deadlock
84/153
PA T B T
1 0.0 6
2 2.0 83 4.0 7
4 5.0 3
SJF
A = (3 + 16 + 9 + 0) / 4 = 7
P4 P3P1
3 160 9
P2
24
8/6/2013 84OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
D L N CPU
8/12/2019 Scheduling Deadlock
85/153
B C
T CPU
C CPU ,
burstCPUnexttheforvaluepredicted2.
burstCPUoflengthactual1.
=
=
+ 1n
thn nt
C, P
:Define4.
10,3.
( ) .11 nnn t +==
8/6/2013 85OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
P L
N CPU B
8/12/2019 Scheduling Deadlock
86/153
8/6/2013 86OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
E E
8/12/2019 Scheduling Deadlock
87/153
A =0
+1=
R =1
+1= O CPU
I , :+1= +(1)1 +
+(1 )+ +(1 )+1 0
S (1 ) 1,
8/6/2013 87OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
E S
8/12/2019 Scheduling Deadlock
88/153
N
PA TT B T
1 0 82 1 4
3 2 9
4
SJF G C
A = (101)+(11)+(172)+53)/4 = 26/4 = 6.5
P1 P1P2
1 170 10
P3
265
P4
8/6/2013 88OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
P S
8/12/2019 Scheduling Deadlock
89/153
A ()
T CPU ( ) P
SJF CPU
P
S
8/6/2013 89OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
E P S
8/12/2019 Scheduling Deadlock
90/153
PA B TT P
1 10 3
2 1 13 2 4
4 1 5
5
P G C
A = 8.2
P2 P3P5
1 180 16
P4
196
P1
8/6/2013 90OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
R R (RR)
8/12/2019 Scheduling Deadlock
91/153
E CPU ( ), 10100 . A , .
I , 1/ CPU . N 1 .
T
P FIFO ,
8/6/2013 91OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
E RR T
Q 4
8/12/2019 Scheduling Deadlock
92/153
Q = 4P B T
1 24
2 3
3 3
T, SJF, 10 100, < 10
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
8/6/2013 92OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
T Q C S T
8/12/2019 Scheduling Deadlock
93/153
8/6/2013 93OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
T T V W
T T Q
8/12/2019 Scheduling Deadlock
94/153
80% of CPU bursts shouldbe shorter than q
8/6/2013 94OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
M Q
8/12/2019 Scheduling Deadlock
95/153
R , : ()
()
P
E : RR
FCFS S :
F ; (.., ). P .
T CPU ; .., 80% RR 20% FCFS
8/6/2013 95OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
M Q S
8/12/2019 Scheduling Deadlock
96/153
8/6/2013 96OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
M F Q
8/12/2019 Scheduling Deadlock
97/153
A ;
M
8/6/2013 97OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
E M
F Q
8/12/2019 Scheduling Deadlock
98/153
F Q T :
0 RR 8 1 RR 16
2 FCFS
S
A 0 FCFS W CPU, 8
I 8 ,
18/6/2013 98
OS Concepts 053006 -Synchronization, Deadlock and
Scheduling
T S
8/12/2019 Scheduling Deadlock
99/153
D
W , ,
M , LWP
K ()
T
K CPU
()
8/6/2013 99OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
MP S
8/12/2019 Scheduling Deadlock
100/153
CPU CPU
,
() , , C,
V
8/6/2013 100OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
NUMA CPU S
8/12/2019 Scheduling Deadlock
101/153
Note that memory-placement algorithms can alsoconsider affinity
8/6/2013 101OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
MP S L B
8/12/2019 Scheduling Deadlock
102/153
I SMP, CPU
, CPU CPU
8/6/2013 102OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
M P
8/12/2019 Scheduling Deadlock
103/153
R
F
M
T
8/6/2013 103OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
M M
S
8/12/2019 Scheduling Deadlock
104/153
S
8/6/2013 104OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
L F
8/12/2019 Scheduling Deadlock
105/153
=
=
=
,
=
V
F , 7 ,
14 , = 2
8/6/2013 105OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
S
8/12/2019 Scheduling Deadlock
106/153
Q
P
G D
R
D T
8/6/2013 106OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
E CPU S
S
8/12/2019 Scheduling Deadlock
107/153
8/6/2013 107OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
E C 6
8/12/2019 Scheduling Deadlock
108/153
8/6/2013 108OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
8/12/2019 Scheduling Deadlock
109/153
C 7: D
8/6/2013OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
109
C 7: D
8/12/2019 Scheduling Deadlock
110/153
M H D
D P D A
D D
R D
8/6/2013 110OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
C O
8/12/2019 Scheduling Deadlock
111/153
T ,
T
8/6/2013 111OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
S M
8/12/2019 Scheduling Deadlock
112/153
S .
R 1, 2, . . ., , , /
E
.
E :
8/6/2013 112OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
D C
Deadlock can arise if fo r conditions hold sim ltaneo sl
8/12/2019 Scheduling Deadlock
113/153
Deadlock can arise if four conditions hold simultaneously.
:
:
: ,
: 0, 1, , 0 1, 1 2, , 1 , 0.
8/6/2013 113OS Concepts 053006 -
Synchronization, Deadlock and
Scheduling
RA G
A set of vertices Vand a set of edges E.
8/12/2019 Scheduling Deadlock
114/153
V :=
1
, 2
, ,
,
= 1, 2, , ,
8/6/2013 114OS Concepts 053006 -
Synchronization, Deadlock andScheduling
RA G
(C.)
P
8/12/2019 Scheduling Deadlock
115/153
P
R T 4
Pi
Pi
Rj
Rj
8/6/2013 115OS Concepts 053006 -
Synchronization, Deadlock andScheduling
E R A G
8/12/2019 Scheduling Deadlock
116/153
8/6/2013 116OS Concepts 053006 -
Synchronization, Deadlock andScheduling
Q?
8/12/2019 Scheduling Deadlock
117/153
03 P 04 R.
R1 01 , R2 02 , R3 01 , R4 03 .
P1 01 R2 01 R1
P2 01 R1, 01 R2 01 R3
P3 01 R3 01 R2
8/6/2013OS Concepts 053006 -
Synchronization, Deadlock andScheduling
117
R A G W A D
8/12/2019 Scheduling Deadlock
118/153
8/6/2013 118OS Concepts 053006 -
Synchronization, Deadlock andScheduling
G W A C B N
D
8/12/2019 Scheduling Deadlock
119/153
8/6/2013 119OS Concepts 053006 -
Synchronization, Deadlock andScheduling
B F
I
8/12/2019 Scheduling Deadlock
120/153
I
I
,
,
8/6/2013 120OS Concepts 053006 -
Synchronization, Deadlock andScheduling
M H
D
E
8/12/2019 Scheduling Deadlock
121/153
E
A
I ;
, UNIX
8/6/2013 121OS Concepts 053006 -
Synchronization, Deadlock andScheduling
D P
;Restrain the ways request can be made
8/12/2019 Scheduling Deadlock
122/153
;
,
R ,
L ;
8/6/2013 122OS Concepts 053006 -
Synchronization, Deadlock andScheduling
D P (C.)
8/12/2019 Scheduling Deadlock
123/153
I ,
P
P ,
8/6/2013 123
OS Concepts 053006 -Synchronization, Deadlock and
Scheduling
D A
S
Requires that the system has some additional a priori informationavailable
8/12/2019 Scheduling Deadlock
124/153
S
T
R ,
8/6/2013 124
OS Concepts 053006 -Synchronization, Deadlock and
Scheduling
S S
W ,
8/12/2019 Scheduling Deadlock
125/153
W ,
.
S ALL P,
+ , <
T : I P ,
W , , , ,
W , +1 ,
8/6/2013 125OS Concepts 053006 -
Synchronization, Deadlock andScheduling
B F
I
8/12/2019 Scheduling Deadlock
126/153
I
I
A
.
8/6/2013 126OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S, U, D S
8/12/2019 Scheduling Deadlock
127/153
8/6/2013 127OS Concepts 053006 -
Synchronization, Deadlock andScheduling
A
S
8/12/2019 Scheduling Deadlock
128/153
S
U
M
U
8/6/2013 128OS Concepts 053006 -
Synchronization, Deadlock andScheduling
B A
M
8/12/2019 Scheduling Deadlock
129/153
M
E W
W
8/6/2013 129OS Concepts 053006 -
Synchronization, Deadlock andScheduling
D S B A
Let n= number of processes, and m = number of resources types.
8/12/2019 Scheduling Deadlock
130/153
V . I = ,
. I , = ,
. I A, = . I , =,
,= , ,
8/6/2013 130OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S A
1. L , .I:
8/12/2019 Scheduling Deadlock
131/153
I: = = = 0, 1, , 1
2. F : =
() I , 4
3. = + = 2
4. I == ,
8/6/2013 131OS Concepts 053006 -
Synchronization, Deadlock andScheduling
RR A P
= . I =
8/12/2019 Scheduling Deadlock
132/153
1. I 2. O,
, 2. I , 3. O ,
3. P
: = =+ ;=
I
I
,
8/6/2013 132OS Concepts 053006 -
Synchronization, Deadlock andScheduling
E B A
5 0 4;3
8/12/2019 Scheduling Deadlock
133/153
3 :
(10 ), (5), (7 )
S 0:
0 0 1 0 7 5 3 3 3 21 2 0 0 3 2 2
2 3 0 2 9 0 2
3 2 1 1 2 2 2
4 0 0 2 4 3 3
8/6/2013 133OS Concepts 053006 -
Synchronization, Deadlock andScheduling
E (C.)
T
8/12/2019 Scheduling Deadlock
134/153
0 7 4 3
1 1 2 2
2 6 0 03 0 1 1
4 4 3 1
T < 1, 3, 4, 2, 0>
8/6/2013 134OS Concepts 053006 -
Synchronization, Deadlock andScheduling
E: 1R (1,0,2)
C R A ( , (1,0,2) (3,3,2)
8/12/2019 Scheduling Deadlock
135/153
0 0 1 0 7 4 3 2 3 01 3 0 2 0 2 0
2
3 2 1 1 0 1 1
4 0 0 2 4 3 1 E < 1, 3, 4, 0, 2>
C (3,3,0) 4 ?
C (0,2,0) 0 ?
8/6/2013 135OS Concepts 053006 -
Synchronization, Deadlock andScheduling
RA G
S
8/12/2019 Scheduling Deadlock
136/153
;
C
R
W ,
R
8/6/2013 136OS Concepts 053006 -
Synchronization, Deadlock andScheduling
RA G
8/12/2019 Scheduling Deadlock
137/153
8/6/2013 137OS Concepts 053006 -
Synchronization, Deadlock andScheduling
U S I RA G
8/12/2019 Scheduling Deadlock
138/153
8/6/2013 138OS Concepts 053006 -
Synchronization, Deadlock andScheduling
RA G
A
S
8/12/2019 Scheduling Deadlock
139/153
T
8/6/2013 139OS Concepts 053006 -
Synchronization, Deadlock andScheduling
D D
A
8/12/2019 Scheduling Deadlock
140/153
D
R
8/6/2013 140OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S I E
R T
M
8/12/2019 Scheduling Deadlock
141/153
N
P . I ,
A 2 ,
8/6/2013 141OS Concepts 053006 -
Synchronization, Deadlock andScheduling
RA G W G
8/12/2019 Scheduling Deadlock
142/153
Resource-Allocation Graph Corresponding wait-for graph
8/6/2013 142OS Concepts 053006 -
Synchronization, Deadlock andScheduling
S I
R T
A
8/12/2019 Scheduling Deadlock
143/153
A
A
. I = ,
.8/6/2013 143OS Concepts 053006 -Synchronization, Deadlock andScheduling
D A
1. L , I:
8/12/2019 Scheduling Deadlock
144/153
() =
() F = 1,2, ,, 0, ; , =
2. F :() ==
()
I , 4
8/6/2013 144OS Concepts 053006 -
Synchronization, Deadlock andScheduling
D A (C.)
3.= + =
8/12/2019 Scheduling Deadlock
145/153
=
2
4.I , , 1 , . M, ==,
Algorithm requires an order of O(m x n2
) operations to detect whether the system is in deadlocked state
8/6/2013 145OS Concepts 053006 -
Synchronization, Deadlock andScheduling
E D A
F 0 4; A (7 ), (2 ), (6 )
8/12/2019 Scheduling Deadlock
146/153
S 0:
0 0 1 0 0 0 0 0 0 0
1 2 0 0 2 0 22 3 0 3 0 0 0
3 2 1 1 1 0 0
4 0 0 2 0 0 2
S
8/6/2013 146OS Concepts 053006 -
Synchronization, Deadlock andScheduling
E (C.)
2
8/12/2019 Scheduling Deadlock
147/153
0 0 0 0
1 2 0 2
2 0 0 1
3
1 0 0
4 0 0 2
S ? C 0,
;
D , 1, 2, 3, 4
8/6/2013 147OS Concepts 053006 -
Synchronization, Deadlock andScheduling
DA U
W, , :
H ?
8/12/2019 Scheduling Deadlock
148/153
H ?
H ?
I ,
.
8/6/2013 148OS Concepts 053006 -
Synchronization, Deadlock andScheduling
R D:
P T
A
A
8/12/2019 Scheduling Deadlock
149/153
A
I ?.
2. H ,
3. R 4. R
5. H
6. I ?
8/6/2013 149OS Concepts 053006 -
Synchronization, Deadlock andScheduling
R D:
R P
8/12/2019 Scheduling Deadlock
150/153
,
,
8/6/2013 150OS Concepts 053006 -
Synchronization, Deadlock andScheduling
E
A system with 05 process.a.Prove that system is Safe?b.P1 Request (0, 4, 3, 0) ?
8/12/2019 Scheduling Deadlock
151/153
b.P1 Request (0, 4, 3, 0) ?
c.P1 Request (0, 4, 1, 0) ?
8/6/2013OS Concepts 053006 -
Synchronization, Deadlock andScheduling
151
E
8/12/2019 Scheduling Deadlock
152/153
8/6/2013OS Concepts 053006 -
Synchronization, Deadlock andScheduling
152
All process came at 0.0.
Calculate average roundabout time?Calculate average waiting time?
For each method of scheduling.
E C 7
8/12/2019 Scheduling Deadlock
153/153
8/6/2013 153OS Concepts 053006 -
Synchronization, Deadlock andScheduling