INTEL CONFIDENTIAL Deadlock Introduction to Parallel Programming – Part 7.

Slides:



Advertisements
Similar presentations
Confronting Race Conditions Intel Software College Introduction to Parallel Programming – Part 4.
Advertisements

Shared-Memory Model and Threads Intel Software College Introduction to Parallel Programming – Part 2.
Implementing Domain Decompositions Intel Software College Introduction to Parallel Programming – Part 3.
Advanced Operating Systems
DEADLOCK. Contents  Principles of deadlock  Deadlock prevention  Deadlock detection.
The Intel® Software Community Real-world resources you can use.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Deadlock Emery Berger and Mark Corner University of Massachusetts.
INTEL CONFIDENTIAL Improving Parallel Performance Introduction to Parallel Programming – Part 11.
Chapter 3 Deadlocks TOPICS Resource Deadlocks The ostrich algorithm
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Tanenbaum Ch 6 Silberschatz Ch 7
Deadlocks. 2 System Model There are non-shared computer resources –Maybe more than one instance –Printers, Semaphores, Tape drives, CPU Processes need.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Deadlock CSCI 444/544 Operating Systems Fall 2008.
02/18/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
The ‘deadlock’ conditions Reviewing some key points concerning the potential for ‘deadlock’ in an operating system.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bridge Crossing Example Traffic only in one direction. Each section.
Chapter 6 Deadlocks Resources Introduction Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
INTEL CONFIDENTIAL Confronting Race Conditions Introduction to Parallel Programming – Part 6.
INTEL CONFIDENTIAL OpenMP for Task Decomposition Introduction to Parallel Programming – Part 8.
INTEL CONFIDENTIAL Why Parallel? Why Now? Introduction to Parallel Programming – Part 1.
INTEL CONFIDENTIAL Reducing Parallel Overhead Introduction to Parallel Programming – Part 12.
INTEL CONFIDENTIAL Parallel Decomposition Methods Introduction to Parallel Programming – Part 2.
INTEL CONFIDENTIAL Finding Parallelism Introduction to Parallel Programming – Part 3.
Recognizing Potential Parallelism Intel Software College Introduction to Parallel Programming – Part 1.
INTEL CONFIDENTIAL Predicting Parallel Performance Introduction to Parallel Programming – Part 10.
1 Processes, Threads, Race Conditions & Deadlocks Operating Systems Review.
Deadlock Questions answered in this lecture: What are the four necessary conditions for deadlock? How can deadlock be prevented? How can deadlock be avoided?
Programming with POSIX* Threads Intel Software College.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
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.
1 Deadlocks 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order Suppose.
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
1 Deadlocks Chapter 3. 2 Resources Examples of computer resources –printers –tape drives –tables Processes need access to resources in reasonable order.
Operating Systems 软件学院 高海昌 Operating Systems Gao Haichang, Software School, Xidian University 22 Contents  1. Introduction** 
1 Deadlocks Chapter Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance.
Deadlocks Silberschatz Ch. 7 and Priority Inversion Problems.
Correcting Threading Errors with Intel® Parallel Inspector.
INTEL CONFIDENTIAL Shared Memory Considerations Introduction to Parallel Programming – Part 4.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All.
Thinking in Parallel – Implementing In Code New Mexico Supercomputing Challenge in partnership with Intel Corp. and NM EPSCoR.
This Time - Deadlock Definition Conditions for deadlocks
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Practice Five Chapter Seven.
Lecture 9 Page 1 CS 111 Online Deadlock Prevention Deadlock avoidance tries to ensure no lock ever causes deadlock Deadlock prevention tries to assure.
CS333 Intro to Operating Systems Jonathan Walpole.
Slide 10-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 10.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Deadlock. Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
Tuning Threaded Code with Intel® Parallel Amplifier.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Sistem Operasi IKH311 Deadlock. 2 Resources Examples of computer resources printers tape drives tables Processes need access to resources in reasonable.
CSE 120 Principles of Operating
Introduction to Operating Systems
Chapter 7: Deadlocks.
ე ვ ი ო Ш Е Т И О А С Д Ф К Ж З В Н М W Y U I O S D Z X C V B N M
Review: Readers-Writers Problem
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Deadlocks Session - 13.
DEADLOCK.
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Introduction to Deadlocks
Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks
Presentation transcript:

INTEL CONFIDENTIAL Deadlock Introduction to Parallel Programming – Part 7

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Review & Objectives Previously: Gave examples of ways that threads may contend for shared resources Describe what race conditions are and explain how to eliminate them in OpenMP code At the end of this part you should be able to: Define deadlock and explain ways to prevent it 2

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Locks Are Dangerous Suppose a lock is used to guarantee mutually exclusive access to a shared variable Imagine two threads, each with its own critical region Thread 1Thread 2 a += 5;b += 5; b += 7;a += 7;a += b; a += 11;b += 11; 3

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Faulty Implementation Thread 1Thread 2 lock (lock_a);lock (lock_b); a += 5;b += 5; lock (lock_b);lock (lock_a); b += 7;a += 7;a += b; unlock (lock_b);unlock (lock_a); a += 11;b += 11; unlock (lock_a);unlock (lock_b); 4

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Faulty Implementation Thread 1Thread 2 lock (lock_a);lock (lock_b); a += 5;b += 5; lock (lock_b);lock (lock_a); b += 7;a += 7;a += b; unlock (lock_b);unlock (lock_a); a += 11;b += 11; unlock (lock_a);unlock (lock_b); 5 What happens if threads are at this point at the same time?

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Deadlock A situation involving two or more threads (processes) in which no thread may proceed because each is waiting for a resource held by another Can be represented by a resource allocation graph A graph of deadlock contains a cycle 6 Thread 1Thread 2 lock_b lock_a wants held by

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. More on Deadlocks A program exhibits a global deadlock if every thread is blocked A program exhibits local deadlock if only some of the threads in the program are blocked A deadlock is another example of a nondeterministic behavior exhibited by a parallel program Adding debugging output to detect source of deadlock can change timing and reduce chance of deadlock occurring 7

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Four Conditions for Deadlock Mutually exclusive access to a resource Threads hold onto resources they have while they wait for additional resources Resources cannot be taken away from threads Cycle in resource allocation graph 8

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Preventing Deadlock Eliminate one of four necessary conditions Don’t allow mutually exclusive access to resource Don’t allow threads to wait while holding resources Allow resources to be taken away from threads Make sure request allocation graph cannot have a cycle 9

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Deadlock Prevention Strategies 10 Don’t allow mutually exclusive access to resource Make resource shareable. Don’t allow threads to wait while holding resources Only request resources when have none. That means only hold one resource at a time or request all resources at once. Allow resources to be taken away from threads Allow preemption. Works for CPU and memory. Doesn’t work for locks. Ensure no cycle in request allocation graph Rank resources. Threads must acquire resources in order.

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Correct Implementation Thread 1Thread 2lock (lock_a); a += 5;lock (lock_b); lock (lock_b);b += 5; b += 7;a += 7;a += b; unlock (lock_b);unlock (lock_a); a += 11;b += 11; unlock (lock_a);unlock (lock_b); 11 Threads must lock lock_a before lock_b

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. Another Problem with Locks Every call to function lock should be matched with a call to unlock, representing the start and the end of the critical section A program may be syntactically correct (i.e., may compile) without having matching calls A programmer may forget the unlock call or may pass the wrong argument to unlock A thread that never releases a shared resource creates a deadlock 12

Copyright © 2009, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. * Other brands and names are the property of their respective owners. References Andrea C. Arpaci-Dusseau and Remzi H. Arpaci-Dusseau, “Deadlock”, CS 537, Introduction to Operating Systems, Computer Sciences Department, University of Wisconsin- Madison. Jim Beveridge and Robert Wiener, Multithreading Applications in Win32®, Addison-Wesley (1997). Richard H. Carver and Kuo-Chung Tai, Modern Multithreading: Implementing, Testing, and Debugging Java and C++/Pthreads/ Win32 Programs, Wiley-Interscience (2006). Michael J. Quinn, Parallel Programming in C with MPI and OpenMP, McGraw-Hill (2004). Brent E. Rector and Joseph M. Newcomer, Win32 Programming, Addison-Wesley (1997). N. Wirth, Programming in Modula-2, Springer (1985). 13