Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS 3763 - Operating System Concepts UCF, Spring 2004.

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
Synchronization and Deadlocks
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
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.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Interprocess Communication
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
6: Process Synchronization 1 1 PROCESS SYNCHRONIZATION I This is about getting processes to coordinate with each other. How do processes work with resources.
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.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
CS444/CS544 Operating Systems Synchronization 2/14/2007 Prof. Searleman
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Module 6: Synchronization 6.1 Background 6.2 The Critical-Section.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
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.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
Concurrency, Mutual Exclusion and Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 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.
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.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CS4315A. Berrached:CMS:UHD1 Process Synchronization Chapter 8.
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.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
Process Synchronization
Chapter 5: Process Synchronization
Background on the need for Synchronization
Process Synchronization
G.Anuradha Reference: William Stallings
Chapter 5: Process Synchronization
143a discussion session week 3
Topic 6 (Textbook - Chapter 5) Process Synchronization
Module 7a: Classic Synchronization
Lecture 2 Part 2 Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Synchronization Tools
CSE 542: Operating Systems
Presentation transcript:

Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004

Chapter 7 -2 COOPERATING PROCESSES Independent processes cannot affect or be affected by the execution of another process. Dependent processes can affect or be affected by the execution of another process –a.k.a., Cooperating Processes Processes may cooperate for: –Information sharing –Computation speed-up (Requires 2 or more CPUs) –Modularity –Convenience

Chapter 7 -3 REQUIREMENTS FOR COOPERATION In order to cooperate, processes must be able to: –Communicate with one another Passing information between two or more processes –Synchronize their actions coordinating access to shared resources –hardware (e.g., printers, drives) –software (e.g., shared code) –files (e.g., data or database records) –variables (e.g., shared memory locations) Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires synchronization mechanisms to ensure the orderly execution of cooperating processes –Synchronization itself requires some form of communication

Chapter 7 -4 PROCESS SYNCHRONIZATION Particularly important with concurrent execution Can cause two major problems: –Race Condition - When two or more cooperating processes access and manipulate the same data concurrently, and the outcome of the execution depends on the order in which the access takes place. –Deadlock (Chapter 8) - When two or more waiting processes require shared resource for their continued execution but the required resources are held by other waiting processes

Chapter 7 -5 RACE CONDITION Cooperating processes have within their programs “critical sections” –A code segment during which a process accesses and changes a common variable or data item. –When one processes is in its critical section, no other process must execute in its own critical section. –Execution of critical sections with respect to the same shared variable or data item must be mutually exclusive A race condition occurs when two processes execute critical sections in a non-mutually exclusive manner.

Chapter 7 -6 RACE CONDITION EXAMPLES File Level Access –Editing files in a word processor Record Level Access –Modifying a data base record Shared Variable Level P1P2:LOAD XX = X+1STORE X: Final value for X based on execution sequence

Chapter 7 -7 RACE CONDITION EXAMPLES (cont.) Think of concurrent access as a series of sequential instructions with respect to the shared variable, data or resource. If no interrupts during each code section: X = 1051 If interrupts do occur results may vary: X = 51 or 1050

Chapter 7 -8 PREVENTING RACE CONDITIONS Two options (policies) for preventing race conditions: –we must make sure that each process executes its critical section without interruption (PROBLEMS????) –make other processes wait until the current process completes execution of its critical section Any mechanism for solving the critical section problem must meet the following: –Mutual Exclusion - Only one process at a time may execute in its critical section –Progress - Processes must be allowed to execute their critical sections at some time –Bounded Waiting - Cannot prevent a process from executing its critical section indefinitely

Chapter 7 -9 SOLUTIONS TO CRITICAL SECTION PROBLEM Text book contains various software and hardware solutions to the critical section problem: –Algorithm 1 (software/shared memory): Uses turn variable to alternate entry into critical sections between two processes Assures mutual exclusion but not progress requirement –Algorithm 2 (software/shared memory): Uses flag variables to show requests by processes wishing to enter their critical sections. Assures mutual exclusion but not progress requirement –Algorithm 3 (software/shared memory): Uses flags to show requests, then turn to break tie Meets all three requirements but only for two processes

Chapter SOLUTIONS TO CRITICAL SECTION PROBLEM (cont.) Swap/Test-and-Set (hardware/software/shared memory) Executed as atomic or indivisible instructions. Allows process to test status of a “lock” variable and set lock at same time. Can execute critical section only if unlocked. Can be used to simplify programming of synchronization algorithms.

Chapter SOLUTIONS (cont.) Previous examples require: –OS to provide shared memory locations for variables (turn, flags, locks) –But programmers are responsible for how that shared memory is used. Must write lots of code to support these types of solutions Must write correct code Algorithms 1, 2 & 3 (even with hardware support) become very complicated when more than two processes require access to critical sections referencing the same shared variable/resource.

Chapter SOLUTIONS (cont.) Need more robust solution: –Should be managed by the OS or supported by HLL –Should work with two or more processes –Should not require application process control or masking of interrupts –Should be workable in multi-processor environments (parallel systems) –Should keep processes from executing in the running state (busy/waiting loops or no-ops) while waiting their turn Must also meet our three requirements: –Mutual exclusion, progress, bounded waiting

Chapter ROBUST SOLUTIONS Critical Regions –High Level Language (HLL) construct for controlling execution of critical sections –Code oriented solution –Regions referring to the same shared variable exclude each other in time. Monitors –High Level Language (HLL) construct for managing the shared variable/resource referenced in critical sections –More object- or data-oriented solution –allows the safe sharing of an abstract data type among concurrent processes

Chapter ROBUST SOLUTIONS (cont.) Semaphores –Can be managed by OS or applications programmer –Processes execute P( ) operation before entering critical section –Processes execute V( ) operation after leaving critical section –P( ) and V( ) can be a type of system call

Chapter SEMAPHORES Uses a shared variable s (can be owned by OS) –Initialized to “1” P(s) - Atomic Operation (aka wait) –Decrement value of s by 1 –If s<0, block process Move process from running state to wait_semaphore_s queue V(s) - Atomic Operation (aka signal) –Increment value of s by 1 –If s <=0, unblock a waiting process Move process from wait_semaphore_s queue to ready queue Usually use FCFS/FIFO to ensure progress

Chapter SEMAPHORES (cont.) Semaphores can be used for more than just critical section solutions –Can be used to control access to resources for example, printers, files, records) The P( ) and V( ) operations described in previous slide use a “counting” semaphore. –Negative values of s tell how many processes are waiting to access the share resource associated with the semaphore. –Can initialize s to number other than 1 if more instances of the resource (e.g., printer) exist