Synchronization. Peter J. Denning CS471/CS571. Copyright 2001, by Peter Denning

Similar documents
Synchronization Classic Problems

CSE 4/521 Introduction to Operating Systems

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

Process Synchronization

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2.

CS370 Operating Systems

Concurrency and Synchronisation

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

Concurrency and Synchronisation

Department of CSIT ( G G University, Bilaspur ) Model Answer 2013 (Even Semester) - AR-7307

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

High-level Synchronization

Classic Problems of Synchronization

CS370 Operating Systems

Process Synchronization

Synchronization Basic Problem:

Semaphores. To avoid busy waiting: when a process has to wait, it will be put in a blocked queue of processes waiting for the same event

Semaphores. Semaphores. Semaphore s operations. Semaphores: observations

Process Synchronization

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 7: Process Synchronization. Background

Chapter 7: Process Synchronization. Background. Illustration

Prof. Hui Jiang Dept of Computer Science and Engineering York University

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

Process Coordination

Concept of a process

Process Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

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

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

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

Process Synchronization

Semaphores (by Dijkstra)

More Synchronization; Concurrency in Java. CS 475, Spring 2018 Concurrent & Distributed Systems

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Module 6: Process Synchronization

Multitasking / Multithreading system Supports multiple tasks

Chapter 7: Process Synchronization!

Lesson 6: Process Synchronization

CS 153 Design of Operating Systems Winter 2016

Process Synchronization

Process Synchronization(2)

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation

CS3502 OPERATING SYSTEMS

OS Process Synchronization!

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

Chapter 6: Process Synchronization

Process Synchronization(2)

CSE Traditional Operating Systems deal with typical system software designed to be:

Process Management And Synchronization

CSE 120. Fall Lecture 6: Semaphores. Keith Marzullo

Processes. Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra

Concurrency. Chapter 5

Chapter 2 Processes and Threads

Chapter 5: Process Synchronization

CSC501 Operating Systems Principles. Process Synchronization

Introduction to Operating Systems

Concurrency: Deadlock and Starvation. Chapter 6

Synchronization Principles II

Semaphores. A semaphore is an object that consists of a. methods (e.g., functions): signal and wait. semaphore. method signal. counter.

Chapter 6: Process Synchronization

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

CS370 Operating Systems Midterm Review

Chapter 5: Process Synchronization

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

Process Synchronization(2)

CHAPTER 6: PROCESS SYNCHRONIZATION

Lecture 6 (cont.): Semaphores and Monitors

1. Motivation (Race Condition)

CS3733: Operating Systems

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Process Synchronization. studykorner.org

Operating Systems. User OS. Kernel & Device Drivers. Interface Programs. Interprocess Communication (IPC)

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

Process Synchronization

2 Programs and processes

Chapter 5: Process Synchronization

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

CSE Opera,ng System Principles

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

Midterm Exam. October 20th, Thursday NSC

Interprocess Communication By: Kaushik Vaghani

Chapter 6: Process Synchronization

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

UNIX Input/Output Buffering

9/29/2014. CS341: Operating System Mid Semester Model Solution Uploaded Semaphore ADT: wait(), signal()

Real-Time Operating Systems M. 5. Process Synchronization

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Concurrency pros and cons. Concurrent Programming Problems. Linked list example. Linked list example. Mutual Exclusion. Concurrency is good for users

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

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

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

CS 318 Principles of Operating Systems

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

CSE 120 Principles of Operating Systems Spring 2016

Transcription:

Synchronization Peter J. Denning CS471/CS571 Copyright 2001, by Peter Denning

What is synchronization? Requirement that one process stop to wait to pass a point until another process sends a signal. The waiting point represents a condition that must be true for subsequent execution to be valid. The signal represents the event of the condition becoming true. Semaphores directly implement the requirement. 2001 by Peter J. Denning 2

Time Lines P1 A P2 B P2 P2 cannot cannot pass pass B until until P1 P1 passes passes A A 2001 by Peter J. Denning 3

Time Lines Signal B P1 A P2 B P2 P2 cannot cannot pass pass B until until P1 P1 passes passes A A Await A Signal Signal B = signal(sem) Await Await A = wait(sem) Guarantees tb tb > > ta ta 2001 by Peter J. Denning 4

Common Examples Process ordering Mutual exclusion Pool control Producer-consumer Readers-writers Private semaphore and I/O signalling Monitors 2001 by Peter J. Denning 5

Process Ordering Precedence ordering: one process cannot begin execution until another has finished. Terminate the first process with a signal semaphore to the second. P2sem: init c 0 P1: actions signal(p2sem) P2: wait(p2sem) actions 2001 by Peter J. Denning 6

Mutual Exclusion Allow only one of several processes in a critical section at the same time Prevent race conditions with shared data processed by the critical section. mutex: init c 1 P1: wait(mutex) critical section signal(mutex) P2: wait(mutex) critical section signal(mutex) 2001 by Peter J. Denning 7

Pool Control Set of identical resource units h = GetUnit( ) -- wait until unit free ReturnUnit(h) -- allow waiter to go GetUnit wait(pool)... return h ReturnUnit(h)... signal(pool) return I(pool)=N 2001 by Peter J. Denning 8

Producer-Consumer Process P produces sequence of items x1,x2,x3,... Items stored in order in a buffer Consumer C consumes items from the buffer in the same order, once each Correct operation: output of C identical to output of P (no duplicates, no losses) 2001 by Peter J. Denning 9

Producer-Consumer Buffer is bounded, can hold up to N items. Stop P when buffer full. Stop C when buffer empty. Semaphores: empty: counts number of empty buffer slots, initially N full: counts number of full buffer slots, initially 0 Stop P: wait(empty) Stop C: wait(full) After insert: P says signal(full) After removal: C says signal (empty) 2001 by Peter J. Denning 10

P x1,x2,x3,... buffer C x1,x2,x3,... 2001 by Peter J. Denning 11

P x1,x2,x3,... buffer C x1,x2,x3,... wait(empty) insert signal(full) wait(full) insert signal(empty) 2001 by Peter J. Denning 12

Readers-Writers Shared file Multiple readers and writers Writers exclude readers and other writers Readers exclude writers but not other readers Preventing starvation under load priority to readers? priority to writers? alternating? 2001 by Peter J. Denning 13

Dining Philosophers Five philosophers, round table, five plates, five forks alternating (Dijkstra 1965) Philosopher comes to assigned place, eats, and departs at random times Philosopher needs left and right forks to eat All philosophers follow the same program How to prevent deadlock? Must monitor global table state 2001 by Peter J. Denning 14

Private Semaphore Semaphore reserved for private waiting-use by a process Reserve semaphore indices j=1,...,n for private semaphores. Then j=n+1,...,m are sharable semaphores. Only process i is allowed to call wait(i) Private semaphores useful for synchronizing processes simulating procedure calls where process must wait for a return 2001 by Peter J. Denning 15

Private Semaphore Example of a disk driver process serving block-move requests from user processes Work queue on disk driver collects user requests, driver serves them one at a time driver uses STARTIO to pass task to disk disk uses completion interrupt to signal done disk interrupt handler signals driver to restart driver signals user process to restart 2001 by Peter J. Denning 16

DD: repeat { (i,a,b,rw,sz) = GetMsg() STARTIO(a,b,rw,sz) wait(pid) signal(i) } disk Pi:... PutMsg(DD,pid,a,b,r,sz) wait(pid)... IH[disk]: signal(dd) return 2001 by Peter J. Denning 17

DD: repeat { (i,a,b,rw,sz) = GetMsg() STARTIO(a,b,rw,sz) wait(pid) signal(i) } 2 1 Pi:... PutMsg(DD,pid,a,b,r,sz) wait(pid)... 5 IH[disk]: signal(dd) return 4 3 disk 2001 by Peter J. Denning 18

Monitors A high level language synchronization structure (Hoare 1978) Compiler translates monitor into proper semaphore patterns Much improved programming reliability 2001 by Peter J. Denning 19

Monitors See the more complete description of Monitors in separate slide presentation. 2001 by Peter J. Denning 20