avoiding l iveness hazards
Download
Skip this Video
Download Presentation
Avoiding L iveness hazards

Loading in 2 Seconds...

play fullscreen
1 / 16

Avoiding L iveness hazards - PowerPoint PPT Presentation


  • 101 Views
  • Uploaded on

Avoiding L iveness hazards. Indiscriminate use of locking Lock-ordering deadlocks Incorrect use of thread pools Resource deadlocks Tradeoff between safety and liveness Example Dining philosopher’s problem Database transactions recover by aborting transactions

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Avoiding L iveness hazards' - leon


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
avoiding l iveness hazards
Avoiding Liveness hazards
  • Indiscriminate use of locking
    • Lock-ordering deadlocks
  • Incorrect use of thread pools
    • Resource deadlocks
  • Tradeoff between safety and liveness
  • Example
    • Dining philosopher’s problem
  • Database transactions recover by aborting transactions
  • Deadlocks are non-deterministic
dynamic lock order deadlocks
Dynamic lock-order deadlocks
  • How to fix such deadlocks?
resource deadlocks
Resource deadlocks
  • Task requires two resources
  • Tasks from two threads acquire the two resources in opposite order
    • Resource deadlocks
avoiding diagnosing deadlocks
Avoiding/diagnosing deadlocks
  • Not acquire more than one lock
    • Not practical
  • Lock-ordering protocol for locks acquired together
  • Use open calls
    • synchronized (this) { o.foo(); } -- ?
  • Timed lock attempts
    • Back off and try again
    • random backoff
starvation
Starvation
  • Perpetually denied acess to resources
    • E.g, CPU cycles
  • Inappropriate use of thread priorities
  • Non terminating constructs
    • Infinite loops
    • Resource waits
  • Poor responsiveness
    • GUI applications
    • Use background threads for processing
livelock
Livelock
  • Thread not blocked
    • Does not make progress however
    • Operation fails repeatedly
      • E.g., processing a message type
  • Introduce randomness to avoid livelocks
performance and scalability
Performance and Scalability
  • Threads for improved performance
  • Overheads
    • Coordinating between threads
    • Context switching
    • Thread creation and teardown
    • Scheduling overhead
  • Greater throughput than overheads – beneficial
  • To achieve better performance
    • Utilize processing resources effectively
    • Enable program to exploit addl. processing resources
scalability versus performance
Scalability versus Performance
  • Performance
    • “how fast”
    • Same work with less effort
      • E.g., reuse cache results
  • Scalability
    • “how much”
    • More work with more resources
    • Increases amount of work to be done
      • Divide into tasks
      • Consolidate tasks
amdahl s law
Amdahl’s law
  • Speedup <= 1/(F + (1 – F)/N)
    • F: fraction of work done serially
context switching
Context switching
  • Manipulate shared data structures in the OS
    • Less CPU available for program
  • Data required not in local processor cache
    • Cache misses initially
      • Threads run slowly
    • Minimum time for each thread to run
      • Amortizes cost of context switching
      • Reduces responsiveness
  • More blocking = more context switches
  • vmstat on Unix reports number of context switches
memory synchronization
Memory synchronization
  • Visibility guarantees of synchronization causes
    • Memory barriers
      • Flush/invalidate caches
      • Flush hardware write buffers
      • Inhibit compiler optimizations
  • Uncontended vs Contended synchronization
  • Uncontended
    • Perform optimizations
      • E.g., lock object accessible by only one thread
example1
Example
  • Lock coarsening
blocking
Blocking
  • Spin waiting
  • Suspending blocked thread
    • Unnecessary context switches
reducing lock contention
Reducing lock contention
  • Reduce duration of locks hold
  • Reduce frequency of requests
  • Replace exclusive locks with coordination mechanisms
reducing lock contention1
Reducing lock contention
  • Narrow lock scope
  • Reduce lock granularity
    • Lock splitting
      • Different locks for different variables
    • Lock striping
      • Extension of split to variable sized objects
  • Avoid hot fields
    • E.g., addQuery, addUser
  • Alternative to exclusive locks
    • ReadWriteLocks
  • Avoid object pooling
    • Coordination to the pool structure
ad