Announcements. Office hours. Reading. W office hour will be not starting next week. Chapter 7 (this whole week) CMSC 412 S02 (lect 7)

Similar documents
Part II Process Management Chapter 6: Process Synchronization

Chapter 7: Process Synchronization. Background. Illustration

CS586: Distributed Computing Tutorial 3

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Process Coordination

SAMPLE MIDTERM QUESTIONS

אלגוריתמי הסנכרון. 1. Lock Variables Mutual Exclusion: No Deadlock-Free: Yes Starvation-Free: No

Process Synchronization

Chapter 7: Process Synchronization. Background

Last class: Today: CPU Scheduling. Start synchronization

Process Synchronization

Concurrency: Mutual Exclusion and Synchronization

Process Synchronization

Operating Systems CMPSC 473. Synchronization February 21, Lecture 11 Instructor: Trent Jaeger

Synchronization for Concurrent Tasks

Part III Synchronization Software and Hardware Solutions

1 Algorithmic Solution

Dept. of CSE, York Univ. 1

! Why is synchronization needed? ! Synchronization Language/Definitions: ! How are locks implemented? Maria Hybinette, UGA

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Synchronization. Before We Begin. Synchronization. Credit/Debit Problem: Race Condition. CSE 120: Principles of Operating Systems.

Concurrency: Mutual Exclusion and

CS370 Operating Systems

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization?

Interprocess Communication 11

QUESTION BANK. UNIT II: PROCESS SCHEDULING AND SYNCHRONIZATION PART A (2 Marks)

Comp 310 Computer Systems and Organization

I613: Formal Methods. Mutual Exclusion Problem

Module 6: Process Synchronization

Process Synchronization. Mehdi Kargahi School of ECE University of Tehran Spring 2008

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background

Process Synchronization

Process Synchronization (Part I)

Synchronization. Before We Begin. Synchronization. Example of a Race Condition. CSE 120: Principles of Operating Systems. Lecture 4.

Chapter 6: Synchronization

SPIN, PETERSON AND BAKERY LOCKS

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018

CSE 120: Principles of Operating Systems. Lecture 4. Synchronization. October 7, Prof. Joe Pasquale

CS4411 Intro. to Operating Systems Exam 1 Fall points 10 pages

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: Process Synchronization Examples

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

CSCI [4 6] 730 Operating Systems. Example Execution. Process [& Thread] Synchronization. Why does cooperation require synchronization?

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS

Interprocess Communication 12

Chapter 6: Process Synchronization

Chapter 5 Asynchronous Concurrent Execution

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Synchronization Spinlocks - Semaphores

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution

Synchronization. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Synchronization Principles I

Process Synchronization(2)

UNIT II PROCESS MANAGEMENT 9

Synchronization API of Pthread Mutex: lock, unlock, try_lock CondVar: wait, signal, signal_broadcast. Synchronization

Example Threads. compile: gcc mythread.cc -o mythread -lpthread What is the output of this program? #include <pthread.h> #include <stdio.

$ %! 0,-./ + %/ 0"/ C (" &() + A &B' 7! .+ N!! O8K + 8 N. (Monitors) 3+!

Lesson 6: Process Synchronization

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 6: Process Synchronization. Module 6: Process Synchronization

Process Synchronization

Introduction to OS Synchronization MOS 2.3

1. Motivation (Race Condition)

Concurrency: a crash course

Chapter 7: Process Synchronization!

PESIT Bangalore South Campus

Process/Thread Synchronization

Lecture 7: Mutual Exclusion 2/16/12. slides adapted from The Art of Multiprocessor Programming, Herlihy and Shavit

Process Synchronization(2)

CS420: Operating Systems. Process Synchronization

CS370 Operating Systems

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Concurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.

Chapters 5 and 6 Concurrency

Chapter 6: Process Synchronization

Process/Thread Synchronization

Chapter 7 Process Synchronization

CSCI 447 Operating Systems Filip Jagodzinski

CIS Operating Systems Synchronization based on Busy Waiting. Professor Qiang Zeng Spring 2018

Synchronization Principles

G52CON: Concepts of Concurrency

Unit 1: Introduction

Module 6: Process Synchronization

Synchronization. Coherency protocols guarantee that a reading processor (thread) sees the most current update to shared data.

Process Synchronization

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Lecture Topics. Announcements. Today: Concurrency: Mutual Exclusion (Stallings, chapter , 5.7)

Synchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution

10/17/2011. Cooperating Processes. Synchronization 1. Example: Producer Consumer (3) Example

Processes. Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra

CS5460: Operating Systems

Concurrency: Mutual Exclusion (Locks)

Module 7: Synchronization Lecture 13: Introduction to Atomic Primitives. The Lecture Contains: Synchronization. Waiting Algorithms.

Concurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.

CSCI 447 Operating Systems Filip Jagodzinski

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Chapter 5: Process Synchronization

Transcription:

Office hours Announcements W office hour will be 10-11 not 11-12 starting next week Reading Chapter 7 (this whole week) 1

Problems with the Producer-Consumer Shared Memory Solution Consider the three address code for the counter Counter Increment Counter Decrement reg 1 = counter reg 2 = counter reg 1 = reg 1 + 1 reg 2 = reg 2-1 counter = reg 1 counter = reg 2 Now consider an ordering of these instructions T 0 producer reg 1 = counter { reg 1 = 5 } T 1 producer reg 1 = reg 1 + 1 { reg 1 = 6 } T 2 consumer reg 2 = counter { reg 2 = 5 } T 3 consumer reg 2 = reg 2-1 { reg 2 = 4 } T 4 producer counter = reg 1 { counter = 6 } T 5 consumer counter = reg 2 { counter = 4 } This should be 5! 2

Defintion of terms Race Condition Where the order of execution of instructions influences the result produced Important cases for race detection are shared objects counters: in the last example Mutual exclusion only one process at a time can be updating shared objects Critical section region of code that updates or uses shared data to provide a consistent view of objects need to make sure an update is not in progress when reading the data need to provide mutual exclusion for a critical section 3

Critical Section Problem processes must request permission to enter the region notify when leaving the region protocol needs to provide mutual exclusion only one process at a time in the critical section ensure progress no process outside a critical section may block another process guarantee bounded waiting time limited number of times other processes can enter the critical section while another process is waiting not depend on number or speed of CPUs or other hardware resources 4

Critical Section (cont) May assume that some instructions are atomic typically load, store, and test word instructions Algorithm #1 for two processes use a shared variable that is either 0 or 1 when P k = k a process may enter the region repeat (while turn!= 0); // critical section turn = 1; // non-critical section until false; repeat (while turn!= 1); // critical section turn = 0; // non-critical section until false; this fails the progress requirement since process 0 not being in the critical section stops process 1. 5

Critical Section (Algorithm 2) Keep an array of flags indicating which processes want to enter the section bool flag[2]; Both processes could be here at the same time repeat flag[i] = true; while (flag[j]); // critical section flag[i] = false; // non-critical section until false; This does NOT work either! possible to have both flags set to 1 6

Combine 1 & 2 Critical Section (Algorithm 3) bool flag[2]; int turn; repeat flag[i] = true; turn = j; while (flag[j]&& turn ==j); // critical section flag[i] = false; // non-critical section until false; This one does work! Why? 7

Critical Section (many processes) What if we have several processes? One option is the Bakery algorithm bool choosing[n]; integer number[n]; choosing[i] = true; number[i] = max(number[0],..number[n-1])+1; choosing[i] = false; for j = 0 to n-1 while choosing[j]; while number[j]!= 0 and ((number[j], j) < number[i],i); end // critical section number[i] = 0 8

Bakery Algorithm - explained When a process wants to enter critical section, it takes a number however, assigning a unique number to each process is not possible it requires a critical section! however, to break ties we can used the lowest numbered process id Each process waits until its number is the highest one it can then enter the critical section provides fairness since each process is served in the order they requested the critical section 9

Synchronization Hardware If it s hard to do synchronization in software, why not do it in hardware? Disable Interrupts works, but is not a great idea since important events may be lost. doesn t generalize to multi-processors test-and-set instruction one atomic operation executes without being interrupted operates on one bit of memory returns the previous value and sets the bit to one swap instruction one atomic operation swap(a,b) puts the old value of b into a and of a into b 10