Avoiding l iveness hazards
This presentation is the property of its rightful owner.
Sponsored Links
1 / 16

Avoiding L iveness hazards PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on
  • Presentation posted in: General

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

Download Presentation

Avoiding L iveness hazards

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


Example

Example


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


  • Login