Presentation is loading. Please wait.

Presentation is loading. Please wait.

0 Synchronization Problem Resource sharing –Requires mutual exclusion –Critical section A code section that should be executed mutually exclusively by.

Similar presentations


Presentation on theme: "0 Synchronization Problem Resource sharing –Requires mutual exclusion –Critical section A code section that should be executed mutually exclusively by."— Presentation transcript:

1 0 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)

2 1 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.

3 2 Indefinite Priority Inversion lock S time preempt J3 (try to lock S) blocked by J3 preempt J3      indefinite blocking !     

4 3 Assumptions No voluntary blocking –Jobs do not suspend themselves, say for I/O operations. Properly nested critical sections –(ex) Properly nested semaphores J i  ..., P  S 1 ,..., P  S 2 ,..., V  S 2 ,..., V  S 1 ,...  J i  ..., P  S 1 ,..., P  S 2 ,..., V  S 1 ,..., V  S 2 ,...  Non-properly nested semaphores

5 4 Description of Basic Protocol If job J blocks higher priority jobs: –J inherits P H, the highest priority of the jobs blocked by J. Priority inheritance is transitive. –If J 3 blocks J 2 and J 2 blocks J 1, J 3 would inherit the priority of J 1 via J 2. When J exits a critical section: –J resumes the priority it had at the point of entry into the critical section.

6 5 Examples for Basic Protocol (1/2) lock S time preempt J3 (try to lock S) blocked by J3 preempt J3 (lock S) j3 inherits priority of J1 arrive unlock Scomplete unlock S push-through blocking

7 6 Examples for Basic Protocol (2/2) J 1  ..., P  S 2 ,..., V  S 2 ,...  J 2  ..., P  S 2 ,..., P  S 1 ,..., V  S 1 ,..., V  S 2 ,...  J 3  ..., P  S 1 ,..., V  S 1 ,...  time preempt J3 (attempt to lock S2) blocked by J2 complete (attempt to lock S1) blocked by J3 unlock S1 unlock S2 unlock S2 lock S2 lock S1 lock S1 unlock S1 lock S2 t0t1t2t3t4t5t6t7t8t9t10t11t12t13 complete transitive blocking nested semaphores

8 7 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 J i which, in turn, is blocked by another job J j.

9 8 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.

10 9 Deadlocks in Basic Protocol J 1  ..., P  S 2 ..., P  S 1 ,...,V  S 1 ...,V  S 2 ,...  J 2  ..., P  S 1 ..., P  S 2 ,...,V  S 2 ...,V  S 1 ,...  lock S1 time preempt J2 lock S2 (try to lock S1) blocked by J2 (try to lock S2) blocked by J1 crossing nested semaphores deadlock!

11 10 Blocking Chains in Basic Protocol J 1  ..., P  S 1 ,..., V  S 1 ,..., P  S 2 ,..., V  S 2 ,...  J 2  ..., P  S 2 ,..., V  S 2 ,...  J 3  ..., P  S 1 ,..., V  S 1 ,...  time preempt J3 (attempt to lock S1) blocked by J3 complete (attempt to lock S2) blocked by J2 unlock S1 unlock S2 unlock S2 lock S2 lock S1 lock S1 unlock S1 lock S2 t0t1t2t3t4t5t6t7t8t9t10t11t12t13 complete

12 11 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


Download ppt "0 Synchronization Problem Resource sharing –Requires mutual exclusion –Critical section A code section that should be executed mutually exclusively by."

Similar presentations


Ads by Google