143a discussion session week 3

Slides:



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

Process Synchronization A set of concurrent/parallel processes/tasks can be disjoint or cooperating (or competing) With cooperating and competing processes.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Previously… Processes –Process States –Context Switching –Process Queues Threads –Thread Mappings Scheduling –FCFS –SJF –Priority scheduling –Round Robin.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Chapter 6: Process Synchronization
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.
Mutual Exclusion.
Operating Systems ECE344 Ding Yuan Synchronization (I) -- Critical region and lock Lecture 5: Synchronization (I) -- Critical region and lock.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Concurrency.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
University of Pennsylvania 9/19/00CSE 3801 Concurrent Processes CSE 380 Lecture Note 4 Insup Lee.
02/23/2004CSCI 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.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Synchronization CSCI 444/544 Operating Systems Fall 2008.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Process Synchronization Ch. 4.4 – Cooperating Processes Ch. 7 – Concurrency.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Concurrency, Mutual Exclusion and Synchronization.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
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.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
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.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
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.
Interprocess Communication Race Conditions
CSE 120 Principles of Operating
Process Synchronization
Process Synchronization: Semaphores
Background on the need for Synchronization
Chapter 5: Process Synchronization
Process Synchronization - I
CSCI 511 Operating Systems Chapter 5 (Part C) Monitor
Lecture 11: Mutual Exclusion
Topic 6 (Textbook - Chapter 5) Process Synchronization
Lecture 19 Syed Mansoor Sarwar
Module 7a: Classic Synchronization
Outline Distributed Mutual Exclusion Introduction Performance measures
Lecture 2 Part 2 Process Synchronization
Grades.
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
CSE 542: Operating Systems
Don Porter Portions courtesy Emmett Witchel
Presentation transcript:

143a discussion session week 3 Jia Chen 20 Apr 2018 Slides contains some content adapted from http://www.csdl.tamu.edu/~furuta

Announcement HW1 Programming assignment due tonight pdf to Canvas please include your name and student id in the file. Programming assignment Released next week

Process Synchronization Process coordination –interaction of processes in the operating system simultaneously Shared state (e.g., shared memory or shared variable) When concurrent processes interact through shared variables, the integrity of the variables’ data may be violated if the access is not coordinated What is the problem? How is coordination achieved?

Problem Statement Result of parallel computation on shared memory can be nondeterministic Example A = 1; || A = 2; What is the result in A? 1, 2, 3 …? Race condition: (race to completion) Cannot predict what will happen since the result depends on which goes faster What happens if both go at exactly the same speed?

Example Assume that X is a bank account balance Process A: payroll Process B: ATM withdraw Load X, R Add R, 1000 Store R, X Load X, R Add R, -100 Store R, X

If the two processes are executed sequentially, e.g., Load X, R add R, 1000 store R, X ….O.S. context switch add R, -100 If the two processes are executed sequentially, e.g., Load X, R add R, -100 ….O.S. context switch add R, 1000 store R, X Problem occurs!

Basic Assumptions for System Building The order of some operations are irrelevant (some operations are independent) A = 1; || B = 2; Can identify certain segments where interaction is critical Atomic operation(s) must exist in hardware Atomic operation: either happens in its entirety without interruption or not at all Cannot solve critical section problem without atomic operations

Atomic Operations Example, consider the possible outcomes of an atomic and a non- atomic printf printf(“ABC”); || printf(“CBA”); but printf is too big to be atomic (hundreds or thousands of instructions executed, I/O waits, etc.) Commonly-found atomic operations Memory references Assignments on simple scalar (e.g., single bytes or words) Operations with interrupts disabled on uniprocessor

Process Coordination Low-level atomic operations are used to build higher-level ones (more later) E.g., semaphores, monitors, etc. Note: in analysis, no assumption on the relative speed of two processes can be made. Process coordination requires explicit control of concurrency.

Problems: Producer/consumer applications Producer – creates information Consumer – uses information Example – piped applications in Unix cat file.t | eqn | tbl | troff | lpr Bounded buffer between producer and consumer is filled by producer and emptied by consumer

Bounded Buffer

Bounded Buffer Concurrent execution of producer and consumer can cause unexpected results, even if we assume that assignment and memory reference are atomic For example, interleaving can result in counter value of n, n+1, or n-1 when there are n values in the buffer.

Controlling interaction Similar problems even when we are running the same code in the two processes Example: shopping expedition Need to manage interaction in areas in which interaction is critical Critical section: section of code or collection of operations in which only one process may be executing at a given time Example: counter, shopping

Critical Section

Critical Section Critical section operations entry: request permission to enter critical section exit : marks the end of the critical section Mutual exclusion: make sure that only one process is in the critical section at any one time Locking: prevent others from entering the critical section entry then is acquiring the lock exit is releasing the lock

Critical Section Solution must provide Mutual exclusion Progress : if multiple processes are waiting to enter the critical section and there is no process in the critical section, eventually one of the processes will gain entry Bounded waiting: no indefinite postponement A few potential solutions were discussed in class, you should be able to tell if an algorithm satisfies certain requirement, given the code