CSC Multiprocessor Programming, Spring, 2011

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7 - Resource Access Protocols (Critical Sections) Protocols: No Preemptions During Critical Sections Once a job enters a critical section, it cannot.
Mutual Exclusion – SW & HW By Oded Regev. Outline: Short review on the Bakery algorithm Short review on the Bakery algorithm Black & White Algorithm Black.
Operating Systems Part III: Process Management (Process Synchronization)
Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Deadlock and Starvation
Operating Systems: A Modern Perspective, Chapter 8 Slide 8-1 Copyright © 2004 Pearson Education, Inc.
CSC321 Concurrent Programming: §3 The Mutual Exclusion Problem 1 Section 3 The Mutual Exclusion Problem.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Liveness and Performance Issues
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 4: Mutual Exclusion.
Practice Session 7 Synchronization Liveness Guarded Methods Model
Concurrency CS 510: Programming Languages David Walker.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Why The Grass May Not Be Greener On The Other Side: A Comparison of Locking vs. Transactional Memory Written by: Paul E. McKenney Jonathan Walpole Maged.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Internet Software Development Controlling Threads Paul J Krause.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
CSE 451: Operating Systems Section 5 Midterm review.
CSC Multiprocessor Programming, Spring, 2012 Chapter 11 – Performance and Scalability Dr. Dale E. Parson, week 12.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
CSC Multiprocessor Programming, Spring, 2012 Chapter 10 – Avoiding Liveness Hazards Dr. Dale E. Parson, week 11.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
ICS Deadlocks 6.1 Deadlocks with Reusable and Consumable Resources 6.2 Approaches to the Deadlock Problem 6.3 A System Model –Resource Graphs –State.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
Deadlock and Starvation
Process Synchronization
Background on the need for Synchronization
Chapter 5: Process Synchronization
Monitors Chapter 7.
Chapter 7: Deadlocks.
Designing Parallel Algorithms (Synchronization)
Topic 6 (Textbook - Chapter 5) Process Synchronization
COT 5611 Operating Systems Design Principles Spring 2014
The Critical-Section Problem
Module 7a: Classic Synchronization
Mutual Exclusion.
G.Anuradha Ref:- Galvin
Lecture 2 Part 2 Process Synchronization
DPNM Lab. Dept. of CSE, POSTECH
Grades.
Semaphores Chapter 6.
Monitors Chapter 7.
Chapter 6: Process Synchronization
Chapter 6: Synchronization Tools
CSE 153 Design of Operating Systems Winter 2019
EECE.4810/EECE.5730 Operating Systems
Software Engineering and Architecture
Process/Thread Synchronization (Part 2)
Software Engineering and Architecture
CSE 542: Operating Systems
CSE 542: Operating Systems
CSC Multiprocessor Programming, Spring, 2011
Presentation transcript:

CSC 580 - Multiprocessor Programming, Spring, 2011 Chapter 10 – Avoiding Liveness Hazards Dr. Dale E. Parson, week 11

Deadlock Deadly embrace -- multiple threads block waiting for resources held by other threads blocked waiting for resources in a cyclic dependency on those resources. Cycle of lock requests. Some worker threads from assignment 2 enter the CountDownLatch while others enter the CyclicBarrier. A cyclic dataflow dependency such as PipedOutput/Input streams in a signal feedback loop. Other similar + combinations of above.

Lock ordering A program will be free of lock-ordering deadlocks if all threads acquire the locks they need in a fixed global order. (p. 206) Likewise for other blocking resources. Induce an ordering on dynamically determined locks. System.identityHashCode typically returns a unique integer for every unique object. Use it to sort / order multiple dynamic locks. In case of a tie (collision), introduce a tie-breaker lock that must be acquired first. Requires knowing the set of locks at one time.

Hold locks for minimal time Invoking an alien method (method outside of the object managing a lock) with a lock held is asking for liveness trouble. The alien method might acquire other locks (risking deadlock) or block for an unexpectedly long time, stalling other threads that need the lock. (p. 211) Try to organize interrelated data @GuardedBy a lock so you can prepare to manipulate that data, then acquire the lock, manipulate the data, and release the lock as soon as possible, without invoking unbounded alien methods.

Open calls Classes that rely on open calls (calls made with no locks held) are better behaved and composable than classes that make calls with locks held. (p. 211) Liveness analysis that relies exclusively on open calls is easier than one that does not. Loss of atomicity may be a problem. Use a thread interaction protocol that manages critical sections while minimizing locking.

Thread starvation deadlock Tasks that wait for results of other tasks are the primary source. (p. 215) Bounded pools and interdependent tasks do not mix well. Suppose you have a data flow that requires N concurrent tasks in order not to freeze up waiting for work, but your thread pool supports < N tasks.

Thread-starved example from midterm public boolean guardedAdd(IntegerPredicate guard, int incr) { boolean result = false ; while (! result) { // Do not let an interleaved change that preserves the int original = counter.get(); // guard condition cause a failure. if (guard.isSatisfied(original)) { result = counter.compareAndSet(original, origina+incr); } else { break ; } return result ; } // Starvation if guard always met but value always changes concurrently.

Non-starved example from midterm private final AtomicLong getTicket = new AtomicLong(0L); private final AtomicLong callTicket = new AtomicLong(0L); public boolean guardedAdd(IntegerPredicate guard, int incr) { boolean result = false ; long myticket = getTicket .getAndIncrement() while (myticket != callTicket.get()) { } if (guard.isSatisfied(counter)) { // counter is a volatile int here counter += incr ; result = true ; } callTicket.incrementAndGet(); return result ;

Avoiding and diagnosing deadlocks Perform global lock analysis, eliminate cycles. Use timed locks. Why did timeout occur? Deadlock? Infinite loop bug? Time consuming action? If multiple locks are acquired in sequence in the same place in code, it is possible to release the predecessor lock(s) (perhaps the full set), back off and wait, then try again. This approach is nondeterministic but it may work statistically over a large number of attempts. Ethernet (bus) uses an exponential backoff algorithm. Solution must include reducing contention for resources.

Thread dumps SIGQUIT (kill -3) on Unix. Ctrl-\ on Unix, Crtl-Break on Windows. Thread dump includes stacks traces and deadlock information. Explicit locks do not show up in Java 5 thread dumps.

Other liveness hazards Starvation Thread priority is a scheduling hint. Avoid using thread priorities, which may lead to priority inversion and suboptimal scheduling. Poor performance due to poor workload partitioning (Amdahl’s Law in upcoming chapter) or by holding locks too long. Livelock means a running thread cannot progress. Starved thread on slide 7 or a transaction system that always restarts. Retry with random waits and backoffs.