Liveness and Performance Issues

Slides:



Advertisements
Similar presentations
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Advertisements

Operating Systems Mehdi Naghavi Winter 1385.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 14: Deadlock & Dinning Philosophers.
Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Deadlock Prevention, Avoidance, and Detection
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Deadlock Prevention, Avoidance, and Detection.  The Deadlock problem The Deadlock problem  Conditions for deadlocks Conditions for deadlocks  Graph-theoretic.
Synchronization Algorithms and Concurrent Programming
Simulation Verification of Different Constraints in System Level Design in SystemC Piyush Ranjan Satapathy CS220 Class Project Presentation.
Distributed Transaction Management, Fall 2002Lecture 2 / Distributed Deadlock Management Jyrki Nummenmaa
SPL/2010 Liveness And Performance 1. SPL/2010 Performance ● Throughput - How much work can your program complete in a given time unit? ● Example: HTTP.
Monitors Chapter 7. The semaphore is a low-level primitive because it is unstructured. If we were to build a large system using semaphores alone, the.
Chapter 6 Concurrency: Deadlock and Starvation
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
Tanenbaum Ch 6 Silberschatz Ch 7
Starvation and Deadlock
The Banker’s Algorithm for A Single Resource
Deadlock CSCI 444/544 Operating Systems Fall 2008.
Chapter 7 – Deadlock and Indefinite Postponement
Deadlock Detection with One Resource of Each Type (1)
1 Concurrency: Deadlock and Starvation Chapter 6.
CPS110: Deadlock Landon Cox February 5, Concurrency so far  Mostly tried to constrain orderings  Locks, monitors, semaphores  It is possible.
1 Concurrency: Deadlock and Starvation Chapter 6.
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.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
Operating Systems (OS)
More on Semaphores Andy Wang Operating Systems COP 4610 / CGS 5765.
1 MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
CIS Operating Systems Deadlock Professor Qiang Zeng Fall 2015.
Deadlocks. What is a Deadlock “A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set.
Debugging Threaded Applications By Andrew Binstock CMPS Parallel.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
Deadlock Bug Detection Techniques Prof. Moonzoo Kim CS KAIST CS492B Analysis of Concurrent Programs 1.
CS 241 Section Week #7 (10/22/09). Topics This Section  Midterm Statistics  MP5 Forward  Classical Synchronization Problems  Problems.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
Deadlock with powerpoint notes Because deadlock is a difficult concept that often looks easy. I have provided yet MORE notes on deadlock extracted from.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
CSC Multiprocessor Programming, Spring, 2012 Chapter 10 – Avoiding Liveness Hazards Dr. Dale E. Parson, week 11.
Operating Systems Unit 4: – Dining Philosophers – Deadlock – Indefinite postponement Operating Systems.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Deadlock and Starvation
Deadlock CSE451 Andrew Whitaker. Review: What Can Go Wrong With Threads? Safety hazards  “Program does the wrong thing” Liveness hazards  “Program never.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Deadlock Detection & recovery
Classical Synchronization Problems
CS703 - Advanced Operating Systems
Deadlock and Starvation
CSC Multiprocessor Programming, Spring, 2011
Introduction to Operating Systems
Chapter 7 Deadlock.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
Monitors Chapter 7.
CS1550: Quiz #1 Quiz #1.
Liveness And Performance
Review: Readers-Writers Problem
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Monitors Chapter 7.
Conditions for Deadlock
Monitors Chapter 7.
Lecture 19: Deadlock: Conditions, Detection and Avoidance
EECE.4810/EECE.5730 Operating Systems
I, for one, Welcome our new Multicore Overlords …
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Presentation transcript:

Liveness and Performance Issues Deadlock Starvation Livelock Lock contention Lock-free data structures

Deadlock Dining Philosophers Wait-for graph If wait-for graph contains a cycle there is a deadlock Potential deadlock (static property) vs Actual Deadlock (dynamic property)

Avoiding Deadlocks by Choosing Lock Ordering “A program will be free of lock-ordering deadlocks if all threads acquire the locks they need in a fixed global order” Needs a precise definition of “fixed global order” Consider dining philosophers 0 before 1 1 before 2 2 before 3 3 before 4 4 before 0 Seems to be a “fixed global order” but allows deadlock In discrete math this would not be considered an “order” because it is cyclic

Programming Strategies to Avoid Deadlock For intrinsic locks, deadlocks are associated with nested synchronized blocks avoid them when possible E.g. what we did to fix Vector.add for the exam Difficult to analyze when calling alien methods Is the alien method synchronized or not? Hard to tell; not part of the formal interface Use open calls – calls that hold no locks – when calling an alien method

Programming Strategies (2) Induced lock ordering Apologies to Nick T. System.identityHashCode(o) – based on the address of an object int h1 = System.identityHashCode(o1); int h2 = System.identityHashCode(o2); if (h1<h2) synchronized(o1) {synchronized(o2) {…}}} else if (h2<h1) synchronized(o2) {synchronized(o1) {…}}} else // bad luck! synchronized(tieLock) {synchronized(o1) {synchronized(o2) {…}}}} Unappealing or unworkable for large object collections

Strategies (3) java.util.concurrent.locks.Lock classes Method Summary void lock() Acquires the lock. void lockInterruptibly() Acquires the lock unless the current thread is interrupted. boolean tryLock() Acquires the lock only if it is free at the time of invocation. boolean tryLock(long time, TimeUnit unit) Acquires the lock if it is free within the given waiting time and the current thread has not been interrupted. void unlock() Releases the lock.

On using timeouts The Lock classes allow lock acquisition to be done interruptibly and with a timeout wait() and its java.util.concurrent.locks analog also allow timeouts Using Lock objects instead of intrinsic synch. can help avoid system-wide catatonia, however, Choice of appropriate timeout values can be difficult System can become time-out driven (i.e. crawl)

Locks are not the only problem More generally, access to resources Locks Resource pools – connections, threads Computational results from a Future Process priority if operating using the “run a highest priority process” rule Different potential for deadlock on uniprocessors and multiprocessors

Starvation Even if no deadlock occurs a thread’s work may not actually get done CPU or other resource continually granted to some other purpose Use of priorities is often the source of the problem In Java priorities are only platform-specific hints In other systems they may actually mean something specfic Either is a danger

The “stable priority inversion problem” Thread A is at high priority, waiting for result or resource from Thread C at low priority Thread B at intermediate priority is CPU-bound Thread C never runs, hence thread A never runs Almost lost a Mars-lander mission due to this problem Fix: when a high priority thread waits for a low priority thread, boost the priority of the low-priority thread

Livelock Several threads spend all their time trying to synchronize instead of getting any work done “After you.” No, “after you.” Easy solution: introduce some randomness

Performance Issues Uncontended locking is not typically a big performance penalty Contended locking Hurts scalability: the ability to add more resources to improve performance/solve bigger problems Hurts performance: spend an increasing amount of time processing the locking code itself Reducing contention Reduce the duration for which locks are held (get in get out) Reduce the frequency at which locks are requested (lock splitting and striping) Replace exclusive locks with coordination mechanisms that allow greater concurrency (reader-writer locks are a simple example) But first make it right and only then make it fast.

Or don’t use locking at all! Last 10 years have seen research in so-called “lock-free” data structures Use the low-level atomic operations typically used to implement locks to instead manipulate data structures directly.

Processor Atomic Operations All of the steps in the code below are performed atomically by the processor. Compare and swap definition boolean CAS(word *address, word old, word new) { if *address == old { *address = new; return true } else return false; } Fetch and add definition void FAA(word *address, word n) { *address += n; }

Implementing an intrinsic lock operation with CAS while (true) { while (!CAS(&o.slock, false, true)) {} if (o.lockOwner == currentThreadId) { o.lockCount++; break; } else if (o.lockOwner == null) { o.lockCount = 1; o.lockOwner = currentThreadId; break; } else Scheduler.enqueueAndSleep(o); } o.slock = false;

What about unlock?