CSE 542: Operating Systems

Slides:



Advertisements
Similar presentations
Operating Systems Part III: Process Management (Process Synchronization)
Advertisements

Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
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.
Synchronization Principles Gordon College Stephen Brinton.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
1 Concurrency: Deadlock and Starvation Chapter 6.
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Synchronization Background The Critical-Section.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
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.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Process Synchronization 1. while (true) { /* produce an item and put in nextProduced */ while (count == BUFFER_SIZE) ; // do nothing buffer [in] = nextProduced;
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);
Lecture 6: Process Synchronization Dr. Nermin Hamza 1.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Process Management Deadlocks.
Chapter 6: Process Synchronization
Process Synchronization
Chapter 5: Process Synchronization
Process Synchronization: Semaphores
Background on the need for Synchronization
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization
Topic 6 (Textbook - Chapter 5) Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Module 7a: Classic Synchronization
Lecture 2 Part 2 Process Synchronization
Critical section problem
Grades.
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
CSE 153 Design of Operating Systems Winter 19
Chapter 6: Synchronization Tools
CSE 542: Operating Systems
Presentation transcript:

CSE 542: Operating Systems Cushing 208 usage…. One of the machines was compromised while students were installing the OS Sshd exploit to attack machines in Virginia Tech Precautions: Always use a real root (and other user passwords) Lets use XXXXXXXX for the root password Turn on the security while installing Linux 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Outline Chapter 7: Process Synchronization Critical sections Chapter 8: Deadlocks A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set 3-Aug-19 CSE 542: Operating Systems

Process Synchronization Cooperating processes (threads) sharing data can experience race condition Outcome depends on the particular order of execution Hard to debug; may never occur during normal runs Register1 = counter Register2 = counter Register1 = Register1 + 1 Register2 = Register2 - 1 counter = Register1 counter = Register2 The final value of the shared data depends upon which process finishes last. To prevent race conditions, concurrent processes must be synchronized. 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Critical Section n processes all competing to use some shared data Each process has a code segment, called critical section, in which the shared data is accessed. Problem – ensure that when one process is executing in its critical section, no other process is allowed to execute in its critical section Must satisfy the following requirements: Mutual Exclusion: Only one process should execute in critical section Progress: Scheduling decisions cannot be postponed indefinitely Bounded Wait: A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted. Remember that synchronization techniques themselves do not guarantee any particular execution order 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Approaches Software based flag[i] = true; turn = j while (flag[j] && turn == j); ….. flag[i] = false; Bakery algorithm for multi-process solution Hardware assistance Disable interrupts while accessing shared variables Works for uniprocessor machines TestAndSet and Swap atomic instruction 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Semaphore Wait (or P) Decrement semaphore if > 0, else wait Signal (or V) Increment semaphore Counting semaphore – integer value can range over an unrestricted domain Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement Also known as mutex locks Can implement a counting semaphore S as a binary semaphore Semaphores provide mutual exclusion Spinlocks - CPU actively waits wasting CPU resources. One optimization is to schedule the process to sleep and have the Signal wake the process. Higher overhead 3-Aug-19 CSE 542: Operating Systems

Deadlocks and Starvation Starvation – indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended “Fairness” issue Deadlock – two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes 3-Aug-19 CSE 542: Operating Systems

Classical synchronization problems Bounded buffer problem Producer, consumer problem Can solve using semaphores E.g. buffer for disk operation in file systems Reader-Writers problem Many reader, single writer 3-Aug-19 CSE 542: Operating Systems

Dining Philosopher problem Each process thinks for random intervals, picks up both forks and eats for random interval. Cannot eat with one fork 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Monitors Higher level language construct Implicitly locks an entire function Java synchronized and notify mechanisms 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Database terminology Atomic transaction A sequence of operation either “all” happen or none at all Either “committed” or “aborted” If aborted, transaction is rolled back Log based recovery where each operation is logged. On failure, the log is played back in reverse Redo log Undo log Shared or exclusive Growing and shrinking phase Serializable atomic transactions More later 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Deadlocks Conditions for deadlock: Mutual exclusion: only one process at a time can use a resource. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task. Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0. Deadlock avoidance protocols Ensure that the above condition cannot happen simultaneously Detection and recovery Laissez-faire - typical OS’s assume deadlocks are rare, and detection and avoidance expensive 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Deadlock prevention Mutual Exclusion Some resources are not mutual - read sharing Hold and Wait Whenever a process requests new resource, it does not hold other resources All resources are requested a-priori No preemption Circular Wait impose a total ordering of all resource types; always request resources in increasing order Bankers algorithm: Don’t give out resources unless you can satisfy all outstanding requests Avoiding deadlocks can lead to low utilization 3-Aug-19 CSE 542: Operating Systems

CSE 542: Operating Systems Recovery Terminate process Abort all deadlocked processes Abort one at a time till cycle is eliminated Selecting the victim: Number of resources held by the process Rollback transactions: return to some safe state, restart process for that state. Starvation: same process may always be picked as victim, include number of rollback in cost factor. 3-Aug-19 CSE 542: Operating Systems