- Ch. 10 Avoiding Liveness Hazards
JESPER PEDERSEN NOTANDER
Ch. 10 Avoiding Liveness Hazards J ESPER P EDERSEN N OTANDER - - PowerPoint PPT Presentation
Ch. 10 Avoiding Liveness Hazards J ESPER P EDERSEN N OTANDER Liveness and Safety A liveness property, something good eventually happens. e.g. program termination. A safety property, something bad never happens. e.g.
JESPER PEDERSEN NOTANDER
– something good eventually happens. – e.g. program termination.
– something bad never happens. – e.g. inconsistent shared states.
Resource Deadlock Lock Ordering Deadlock
Resource A
B? try B∞ wait A lock A? try B lock
Resource B Resource A Resource B
A∞ wait
doLeftRight(){ synchronized( ){ synchronized( ){ // do something }}}
synchronized( ){ synchronized( ){ // do something }}}
A B B A
transaction(A, B) { synchronized( ){ synchronized( ){ // do the transaction }}}
B
transaction(A, B) { if (#A > #B) { transfer(A, B); } else if (#A < #B) { transfer(B, A); } else { synchronized( ){ transfer(A, B); }}
synchronized( ) { synchronized( ) { // perform a safe // transfer }}} X Y T
//class Human synchronized left() { // do something }
manipulate(shared); alien.right(); // alien } //class Alien synchronized left() { manipulate(shared); human.left(); // alien }
// do something }
//class Human synchronized left() { // do something }
manipulate(shared); alien.right(); // alien } //class Alien synchronized left() { manipulate(shared); human.left(); // alien }
// do something }
h h.right a a.left a? alien.right h? human.left a∞ alien.right h∞ human.right
//class Human synchronized left() { // do something }
synchronized(this) { manipulate(shared); } alien.right(); // open } //class Alien left() { synchronized(this) { manipulate(shared); } human.left(); // open }
// do something }
Pool A Pool B
Thread ¡X ¡ Thread ¡Y ¡
Task Queue Task X
Task Y
Spawns Awaits result
Thread …
read-Starvation Deadlock Resource Pools
– Unfeasible à lock ordering must be in the design. – Or use explicit locks
– Triggered when sending SIGQUIT to the JVM. – Deadlock identification, less support with Lock.
– Denial of access to resources, e.g. CPU time – Thread priorities causes starvation
– Not as severe as starvation – Heavy processes competing for CPU time
retries of an action that always fail.
– Common source of failure, error-recovery code.
in a way that makes no further progress possible.
– Solution: Introduce some randomness
deadlock.
– It must be handled already at design time. – Open calls is effective at minimizing this hazard.
deadlock, resource starvation, and livelock.