OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL. Chap. 2.2 Interprocess Communication

Similar documents
C09: Process Synchronization

Chapter 2 Processes and Threads

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

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

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018.

PROCESS SYNCHRONIZATION

Operating systems. Lecture 3 Interprocess communication. Narcis ILISEI, 2018

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

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Running. Time out. Event wait. Schedule. Ready. Blocked. Event occurs

Lecture 4: Inter-Process Communication (Jan 27, 2005)

7: Interprocess Communication

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

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

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

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

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Section I Section Real Time Systems. Processes. 1.4 Inter-Processes Communication (part 1)

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread

Process Synchronization - I

Synchronization I. To do

CS450/550 Operating Systems

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

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

Synchronization I q Race condition, critical regions q Locks and concurrent data structures q Next time: Condition variables, semaphores and monitors

Synchronization I. Today. Next time. Race condition, critical regions and locks. Condition variables, semaphores and Monitors

CS450/550 Operating Systems

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

Synchronization I. Today. Next time. Monitors. ! Race condition, critical regions and locks. ! Condition variables, semaphores and

Concurrency and Synchronisation

Concurrency and Synchronisation

Synchronization Principles I

Course Description: This course includes the basic concepts of operating system

What are they? How do we represent them? Scheduling Something smaller than a process? Threads Synchronizing and Communicating Classic IPC problems

Roadmap. Shared Variables: count=0, buffer[] Producer: Background. Consumer: while (1) { Race Condition. Race Condition.

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

IT 540 Operating Systems ECE519 Advanced Operating Systems

Modern Computers often do lots of things at the same time (web servers, accessing disks, background processes waiting for s,...).

CS 153 Design of Operating Systems Winter 2016

Concept of a process

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

Chapters 5 and 6 Concurrency

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

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang

Introduction to Operating Systems

Global Environment Model

More on Synchronization and Deadlock

Operating Systems. Synchronisation Part I

Concurrency. Chapter 5

Interprocess Communication and Synchronization

IV. Process Synchronisation

EECS 482 Introduction to Operating Systems

POSIX Threads: a first step toward parallel programming. George Bosilca

Background. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling.

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

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

Last Class: Synchronization

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

CPS 110 Midterm. Spring 2011

Implementing Mutual Exclusion. Sarah Diesburg Operating Systems CS 3430

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

Introduction to OS Synchronization MOS 2.3

Chap. 3. Input/Output

Dealing with Issues for Interprocess Communication

MODERN OPERATING SYSTEMS

Process Synchronization

CS 333 Introduction to Operating Systems. Class 4 Concurrent Programming and Synchronization Primitives

Chapter 2 - Processes and Threads

Threads. Concurrency. What it is. Lecture Notes Week 2. Figure 1: Multi-Threading. Figure 2: Multi-Threading

Midterm Exam. October 20th, Thursday NSC

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Locks. Dongkun Shin, SKKU

Background. Old Producer Process Code. Improving the Bounded Buffer. Old Consumer Process Code

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

1995 Paper 10 Question 7

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

CS370 Operating Systems

Synchronization Principles

Synchronising Threads

Synchronization for Concurrent Tasks

CS370 Operating Systems

Mutex Implementation

Process Synchronization (Part I)

Threads and Critical Sections. Otto J. Anshus, Thomas Plagemann, Tore Brox-Larsen, Kai Li

Threading and Synchronization. Fahd Albinali

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

Today: Synchronization. Recap: Synchronization

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

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

Chapter 1 Introduction

CS 450 Exam 2 Mon. 4/11/2016

Lecture Outline. CS 5523 Operating Systems: Concurrency and Synchronization. a = 0; b = 0; // Initial state Thread 1. Objectives.

Concurrency: a crash course

Concurrent & Distributed Systems Supervision Exercises

Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux

High-level Synchronization

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Frequently asked questions from the previous class survey

Transcription:

OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Chap. 2.2 Interprocess Communication Annotated by B. Hirsbrunner, University of Fribourg, 2011 Lecture 5, 18 October 2011 1

2.2.1 Race Conditions Fig. 2-8. Two processes want to access shared memory at the same time

2.2.2 Critical Regions Enter CR Critical Region (CR) Leave CR (1) Door is always open (2) Door is closed or open (1) (2) (1) (1) time Four conditions to provide mutual exclusion 1) No two processes simultaneously in critical region 2) No assumptions made about speeds or numbers of CPUs 3) No process running outside its critical region may block another process 4) No process must wait forever to enter its critical region 3

2.2.2 Critical Regions Fig. 2-9. Mutual exclusion using critical regions

2.2.3 Mutual Exclusion with Busy Waiting Proposals for achieving mutual exclusion: Disabling interrupts Lock variables Strict alternation Peterson's solution The TSL instruction

Disabling Interrupts On a single processor Disable all interrupts just before entering its critical Re-enable them just before leaving Hint: The CPU is only switched from process to process as a result of clock or other interrupts. On a multiprocessor or multicore This solution does not work! Hint: Disabling the interrupts of one CPU does not prevent other CPUs from interfering with operations the first CPU is performing. 6

Lock Variables A not working software solution Share a (lock) variable, initially set to 0. When a process wants to enter its critical region, it first tests the lock. If the lock is 0, the process sets it to 1 and enters the critical region. Hint: This solution has exactly the same fatal flow as the spooler directory example (cf. fig. 2-8). Remark: But this solution works with firmware support, e.g. TSL instruction, cf. fig. 2-12 below. 7

Strict Alternation Process 0 Process 1 Fig. 2-9. An algorithmic solution to the critical region problem 8

Peterson's Solution Fig. 2-11. Peterson s solution for achieving mutual exclusion

The TSL Instruction Fig. 2-12. Entering and leaving a critical region using the TSL instruction Remark: TSL (Test and Set Lock) reads the contents of the memory word LOCK into register REGISTER and stores a non-zero value at the memory address LOCK. These two operations of reading and storing are done atomically.

The XCHG Instruction Fig. 2-26. Entering and leaving a critical region using the XCHG instruction Remark: XCHG exchanges the contents of two locations atomically (for example a register and a memory word). Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Remark: adding a wakeup bit solves the fatal race condition for this problem, but not for all problems! 2.2.4 Sleep and Wakeup enter critical region leave critical region enter critical region leave critical region Fig. 2-13. Producer-consumer problem with fatal race condition 12

2.2.5 Semaphores enter critical region leave critical region 13

leave critical region enter critical region Fig. 2-14. The producer-consumer problem using semaphores 14

2.2.6 Mutexes Fig 2-29. Implementation of mutex lock and mutex unlock Definition A mutex is a variable that can be in one of two states: unlocked (0) or locked (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Mutexes in Pthreads Fig. 2-30. Some of the Pthreads calls relating to mutexes Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

Mutexes in Pthreads : conditional variables Fig. 2-31. Some of the Pthreads calls relating to condition variables Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639

2.2.7 Monitors Fig. 2-15. A monitor Only one monitor procedure at a time can be active

Monitors : an example Fig. 2-16. Outline of producer-consumer problem with monitors only one monitor procedure active at one time buffer has N slots 19

Monitors : the model 20

2.2.8 Message Passing Fig. 2-17. The producer-consumer problem with N messages 21

Barriers Fig. 2-37. Use of a barrier (a) (b) (c) Processes approaching a barrier. All processes but one blocked at the barrier. When the last process arrives at the barrier, all of them are let through. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639