Synchronization Problem • Resource sharing – Requires mutual exclusion

Download Report

Transcript Synchronization Problem • Resource sharing – Requires mutual exclusion

Synchronization Problem
• Resource sharing
– Requires mutual exclusion
– Critical section
• A code section that should be executed mutually exclusively by
tasks
– Semaphore
• One of synchronization primitives
• Assumptions of this paper
– Fixed-priority preemptive scheduling
– A uniprocessor environment
– Binary semaphore (Mutex)
0
Priority Inversion Problem
• Priority inversion
– Phenomenon where a higher priority job is blocked by lower
priority jobs
• Indefinite priority inversion
– Occurs when a task of medium priority preempts a task of
lower priority which is blocking a task of higher priority.
1
Indefinite Priority Inversion
preempt J3
(try to lock S)
blocked by J3
indefinite blocking !

J1
preempt J3

J2
lock S
J3
time
t0
t1
t2
t3
t4
2
Assumptions
• No voluntary blocking
– Jobs do not suspend themselves, say for I/O operations.
• Properly nested critical sections
– (ex)
Ji = {..., P(S1), ..., P(S2), ..., V(S2), ..., V(S1), ...}
Properly nested
semaphores
Ji = {..., P(S1), ..., P(S2), ..., V(S1), ..., V(S2), ...}
Non-properly nested
semaphores
3
Description of Basic Protocol
•
If job J blocks higher priority jobs:
–
•
Priority inheritance is transitive.
–
•
J inherits PH , the highest priority of the jobs blocked by J .
If J3 blocks J2 and J2 blocks J1, J3 would inherit the priority of J1 via J2.
When J exits a critical section:
–
J resumes the priority it had at the point of entry into the critical
section.
4
Examples for Basic Protocol (1/2)
preempt J3
(try to lock S)
blocked by J3
unlock S complete
J1
arrive
J2
j3 inherits
priority of J1
lock S
preempt J3
(lock S)
unlock S
push-through
blocking
J3
time
t0
t1
t2
t3
t4
t5
t6
t7
5
Examples for Basic Protocol (2/2)
J1 = {..., P(S2), ..., V(S2), ...}
J2 = {..., P(S2), ..., P(S1), ..., V(S1), ..., V(S2), ...}
J3 = {..., P(S1) , ..., V(S1), ...}
nested semaphores
transitive blocking
(attempt to lock S2)
blocked by J2
lock unlock complete
S2
S2
J1
preempt J3
lock
S2
(attempt to lock S1) lock
S1
blocked by J3
unlock
S1
unlock
S2
complete
J2
lock
S1
complete
unlock
S1
J3
time
t0 t1
t2
t3
t4
t5
t6
t7
t8
t9
t10 t11 t12
t13
6
Blocking in Basic Protocol
• Three Types of blocking
– Direct blocking
• Ensures the consistency of shared data.
– Push-through blocking
• Prevents indefinite blocking due to priority inversion
– Transitive blocking
• By not-directly involved semaphores which are accessed
in a nested form by blocking jobs.
• Transitive blocking is said to occur if a job J is blocked by Ji
which, in turn, is blocked by another job Jj .
7
Problems of Basic Protocol
• Deadlocks
– Due to crossing nested semaphores
• Long blocking delay
– Due to
• Transitive blocking
– Blocking by not-directly involved semaphores which are
accessed in nested form by blocking jobs.
• Blocking chains
– Blocking can occur sequentially whenever accessing each
semaphore.
8
Deadlocks in Basic Protocol
J1 = {..., P(S2) ..., P(S1),...,V(S1) ...,V(S2),...}
J2 = {..., P(S1) ..., P(S2),...,V(S2) ...,V(S1),...}
preempt J2
lock S2
crossing nested
semaphores
(try to lock S1)
blocked by J2
J1
(try to lock S2)
blocked by J1
lock S1
J2
deadlock!
time
t0
t1
t2
t3
t4
t5
9
Blocking Chains in Basic Protocol
J1 = {..., P(S1), ..., V(S1), ..., P(S2), ..., V(S2), ...}
J2 = {..., P(S2) , ..., V(S2), ...}
J3 = {..., P(S1) , ..., V(S1), ...}
(attempt to lock S1)
lock
blocked by J3
S1
(attempt to lock S2)
blocked by J2
unlock
S1
lock unlock complete
S2
S2
J1
preempt J3
lock
S2
unlock
S2
complete
J2
lock
S1
complete
unlock
S1
J3
time
t0 t1
t2
t3
t4
t5
t6
t7
t8
t9
t10 t11 t12
t13
10
Summary of Basic Protocol
• Basic Idea
– If a job blocks higher priority jobs, it inherits the highest priority of
the jobs blocked by it.
• Three types of blocking
– (1) Direct blocking, (2) push-through blocking, and (3) transitive
blocking
• Controlled priority inversion
– Upper bound on the total blocking delay that a job can encounter
• Can be determined by studying the durations of the critical
sections in *i,j and *i,•,k .
• Problems
– Deadlocks
– Long blocking delay
• Due to transitive blocking and blocking chains
11