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

Size: px
Start display at page:

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

Transcription

1 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

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

3 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

4 2.2.2 Critical Regions Fig Mutual exclusion using critical regions

5 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

6 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

7 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 below. 7

8 Strict Alternation Process 0 Process 1 Fig An algorithmic solution to the critical region problem 8

9 Peterson's Solution Fig Peterson s solution for achieving mutual exclusion

10 The TSL Instruction Fig 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.

11 The XCHG Instruction Fig 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

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

13 2.2.5 Semaphores enter critical region leave critical region 13

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

15 2.2.6 Mutexes Fig 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

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

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

18 2.2.7 Monitors Fig A monitor Only one monitor procedure at a time can be active

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

20 Monitors : the model 20

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

22 Barriers Fig 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

C09: Process Synchronization

C09: Process Synchronization CISC 7310X C09: Process Synchronization Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/29/2018 CUNY Brooklyn College 1 Outline Race condition and critical regions The bounded

More information

Chapter 2 Processes and Threads

Chapter 2 Processes and Threads MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads The Process Model Figure 2-1. (a) Multiprogramming of four programs. (b) Conceptual model of four independent,

More information

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

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 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 2. 3. 8 A N D 2. 3. 1 0 S P R I N G 2018 INTER-PROCESS COMMUNICATION 1. How a process pass information to another process

More information

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

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5 1 Threads The Thread Model (1) (a) Three processes each with one thread (b) One process with three threads 2 1 The Thread Model (2)

More information

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

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug PROCESSES & THREADS Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA 22807 Voice Phone: 540-568-8746; Cell Phone: 443-956-9424 E-mail: abzugcx@jmu.edu OR CharlesAbzug@ACM.org

More information

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

Processes The Process Model. Chapter 2. Processes and Threads. Process Termination. Process Creation Chapter 2 Processes The Process Model Processes and Threads 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling Multiprogramming of four programs Conceptual

More information

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

Motivation of Threads. Preview. Motivation of Threads. Motivation of Threads. Motivation of Threads. Motivation of Threads 9/12/2018. Preview Motivation of Thread Thread Implementation User s space Kernel s space Inter-Process Communication Race Condition Mutual Exclusion Solutions with Busy Waiting Disabling Interrupt Lock Variable

More information

PROCESS SYNCHRONIZATION

PROCESS SYNCHRONIZATION PROCESS SYNCHRONIZATION Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization

More information

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

Operating systems. Lecture 3 Interprocess communication. Narcis ILISEI, 2018 Operating systems Lecture 3 Interprocess communication Narcis ILISEI, 2018 Goals for today Race Condition Critical Region Mutex / Monitor Semaphore Inter-process communication (IPC) A mechanism that allows

More information

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

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies Chapter 2 Processes and Threads Processes The Process Model 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling Multiprogramming of four programs Conceptual

More information

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions Chapter 2 Processes and Threads [ ] 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling 85 Interprocess Communication Race Conditions Two processes want to access shared memory at

More information

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

Running. Time out. Event wait. Schedule. Ready. Blocked. Event occurs Processes ffl Process: an abstraction of a running program. ffl All runnable software is organized into a number of sequential processes. ffl Each process has its own flow of control(i.e. program counter,

More information

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

Lecture 4: Inter-Process Communication (Jan 27, 2005) Lecture 4: Inter-Process Communication (Jan 27, 2005) February 17, 2005 1 Review Q: What is the other command that seems to go hand-in-hand with fork()? A: exec* (6 variants of this command) Q: Suppose

More information

7: Interprocess Communication

7: Interprocess Communication 7: Interprocess Communication Mark Handley Interprocess Communication Processes frequently need to communicate to perform tasks. Shared memory. Shared files. Message passing. Whenever processes communicate,

More information

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

Synchronization. Before We Begin. Synchronization. Example of a Race Condition. CSE 120: Principles of Operating Systems. Lecture 4. CSE 120: Principles of Operating Systems Lecture 4 Synchronization October 7, 2003 Before We Begin Read Chapter 7 (Process Synchronization) Programming Assignment #1 Due Sunday, October 19, midnight Prof.

More information

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

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10) Synchronization CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10) 1 Outline Critical region and mutual exclusion Mutual exclusion using busy waiting Sleep and

More information

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

CSE 120: Principles of Operating Systems. Lecture 4. Synchronization. October 7, Prof. Joe Pasquale CSE 120: Principles of Operating Systems Lecture 4 Synchronization October 7, 2003 Prof. Joe Pasquale Department of Computer Science and Engineering University of California, San Diego 2003 by Joseph Pasquale

More information

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

Synchronization. Before We Begin. Synchronization. Credit/Debit Problem: Race Condition. CSE 120: Principles of Operating Systems. CSE 120: Principles of Operating Systems Lecture 4 Synchronization January 23, 2006 Prof. Joe Pasquale Department of Computer Science and Engineering University of California, San Diego Before We Begin

More information

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

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Processes Prof. James L. Frankel Harvard University Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Process Model Each process consists of a sequential program

More information

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

Section I Section Real Time Systems. Processes. 1.4 Inter-Processes Communication (part 1) EE206: Software Engineering IV 1.4 Inter-Processes Communication 1 page 1 of 16 Section I Section Real Time Systems. Processes 1.4 Inter-Processes Communication (part 1) Process interaction Processes often

More information

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

Preview. The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread Preview The Thread Model Motivation of Threads Benefits of Threads Implementation of Thread Implement thread in User s Mode Implement thread in Kernel s Mode CS 431 Operating System 1 The Thread Model

More information

Process Synchronization - I

Process Synchronization - I CSE 421/521 - Operating Systems Fall 2013 Lecture - VIII Process Synchronization - I Tevfik Koşar University at uffalo September 26th, 2013 1 Roadmap Process Synchronization Race Conditions Critical-Section

More information

Synchronization I. To do

Synchronization I. To do Synchronization I To do q Race condition, critical regions q Locks and concurrent data structures q Next time: Condition variables, semaphores and monitors Cooperating processes Cooperating processes need

More information

CS450/550 Operating Systems

CS450/550 Operating Systems CS450/550 Operating Systems Lecture 2 Processes and Threads Dr. Xiaobo Zhou Department of Computer Science CS450/550 P&T.1 Review: Summary of Lecture 1 Two major OS functionalities: machine extension and

More information

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

Chapter 6: Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Synchronization, Silberschatz, Galvin and Gagne 2009 Outline Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization

More information

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

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T Operating Systems Operating Systems Summer 2017 Sina Meraji U of T More Special Instructions Swap (or Exchange) instruction Operates on two words atomically Can also be used to solve critical section problem

More information

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

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

More information

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

Synchronization I. Today. Next time. Race condition, critical regions and locks. Condition variables, semaphores and Monitors Synchronization I Today Race condition, critical regions and locks Next time Condition variables, semaphores and Monitors Cooperating processes Cooperating processes need to communicate They can affect/be

More information

CS450/550 Operating Systems

CS450/550 Operating Systems CS450/550 Operating Systems Lecture 2 Processes and Threads Palden Lama Department of Computer Science CS450/550 P&T.1 Review: Summary of Lecture 1 Two major OS functionalities: machine extension and resource

More information

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

Learning Outcomes. Concurrency and Synchronisation. Textbook. Concurrency Example. Inter- Thread and Process Communication. Sections & 2. Learning Outcomes Concurrency and Synchronisation Understand concurrency is an issue in operating systems and multithreaded applications Know the concept of a critical region. Understand how mutual exclusion

More information

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

Synchronization I. Today. Next time. Monitors. ! Race condition, critical regions and locks. ! Condition variables, semaphores and Synchronization I Today! Race condition, critical regions and locks Next time! Condition variables, semaphores and Monitors Cooperating processes! Cooperating processes need to communicate They can affect/be

More information

Concurrency and Synchronisation

Concurrency and Synchronisation Concurrency and Synchronisation 1 Sections 2.3 & 2.4 Textbook 2 Making Single-Threaded Code Multithreaded Conflicts between threads over the use of a global variable 3 Inter- Thread and Process Communication

More information

Concurrency and Synchronisation

Concurrency and Synchronisation Concurrency and Synchronisation 1 Learning Outcomes Understand concurrency is an issue in operating systems and multithreaded applications Know the concept of a critical region. Understand how mutual exclusion

More information

Synchronization Principles I

Synchronization Principles I CSC 256/456: Operating Systems Synchronization Principles I John Criswell University of Rochester 1 Synchronization Principles Background Concurrent access to shared data may result in data inconsistency.

More information

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

Course Description: This course includes the basic concepts of operating system Operating Systems Course Title: Operating Systems Full Marks:60+ 20+20 Course No: CSC259 Pass Marks: 24+8+8 Nature of the Course: Theory + Lab Credit Hrs: 3 Course Description: This course includes the

More information

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

What are they? How do we represent them? Scheduling Something smaller than a process? Threads Synchronizing and Communicating Classic IPC problems Processes What are they? How do we represent them? Scheduling Something smaller than a process? Threads Synchronizing and Communicating Classic IPC problems Processes The Process Model a) Multiprogramming

More information

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

Roadmap. Shared Variables: count=0, buffer[] Producer: Background. Consumer: while (1) { Race Condition. Race Condition. CSE / - Operating Systems Fall 0 Lecture - VIII Process Synchronization - I Tevfik Koşar Roadmap Process Synchronization s Critical-Section Problem Solutions to Critical Section Different Implementations

More information

Process Synchronisation (contd.) Operating Systems. Autumn CS4023

Process Synchronisation (contd.) Operating Systems. Autumn CS4023 Operating Systems Autumn 2017-2018 Outline Process Synchronisation (contd.) 1 Process Synchronisation (contd.) Synchronization Hardware 6.4 (SGG) Many systems provide hardware support for critical section

More information

IT 540 Operating Systems ECE519 Advanced Operating Systems

IT 540 Operating Systems ECE519 Advanced Operating Systems IT 540 Operating Systems ECE519 Advanced Operating Systems Prof. Dr. Hasan Hüseyin BALIK (5 th Week) (Advanced) Operating Systems 5. Concurrency: Mutual Exclusion and Synchronization 5. Outline Principles

More information

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

Modern Computers often do lots of things at the same time (web servers, accessing disks, background processes waiting for  s,...). Processes Modern Computers often do lots of things at the same time (web servers, accessing disks, background processes waiting for e-mails,...). Hence, a system supporting multiple processes is needed.

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 9: Semaphores and Monitors Some slides from Matt Welsh Summarize Where We Are Goal: Use mutual exclusion to protect critical sections of code that

More information

Concept of a process

Concept of a process Concept of a process In the context of this course a process is a program whose execution is in progress States of a process: running, ready, blocked Submit Ready Running Completion Blocked Concurrent

More information

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

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Chapters 5 and 6 Concurrency

Chapters 5 and 6 Concurrency Operating Systems: Internals and Design Principles, 6/E William Stallings Chapters 5 and 6 Concurrency Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall Concurrency When several processes/threads

More information

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

CIS Operating Systems Synchronization based on Busy Waiting. Professor Qiang Zeng Spring 2018 CIS 3207 - Operating Systems Synchronization based on Busy Waiting Professor Qiang Zeng Spring 2018 Previous class IPC for passing data Pipe FIFO Message Queue Shared Memory Compare these IPCs for data

More information

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang

Process Synchronization. CISC3595, Spring 2015 Dr. Zhang Process Synchronization CISC3595, Spring 2015 Dr. Zhang 1 Concurrency OS supports multi-programming In single-processor system, processes are interleaved in time In multiple-process system, processes execution

More information

Introduction to Operating Systems

Introduction to Operating Systems Introduction to Operating Systems Lecture 4: Process Synchronization MING GAO SE@ecnu (for course related communications) mgao@sei.ecnu.edu.cn Mar. 18, 2015 Outline 1 The synchronization problem 2 A roadmap

More information

Global Environment Model

Global Environment Model Global Environment Model MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually exclusive in time No assumptions should be made about

More information

More on Synchronization and Deadlock

More on Synchronization and Deadlock Examples of OS Kernel Synchronization More on Synchronization and Deadlock Two processes making system calls to read/write on the same file, leading to possible race condition on the file system data structures

More information

Operating Systems. Synchronisation Part I

Operating Systems. Synchronisation Part I Operating Systems Synchronisation Part I Process Synchronisation How do processes synchronise their operation to perform a task? Key concepts: Critical sections Mutual exclusion Atomic operations Race

More information

Concurrency. Chapter 5

Concurrency. Chapter 5 Concurrency 1 Chapter 5 2 Concurrency Is a fundamental concept in operating system design Processes execute interleaved in time on a single processor Creates the illusion of simultaneous execution Benefits

More information

Interprocess Communication and Synchronization

Interprocess Communication and Synchronization Chapter 2 (Second Part) Interprocess Communication and Synchronization Slide Credits: Jonathan Walpole Andrew Tanenbaum 1 Outline Race Conditions Mutual Exclusion and Critical Regions Mutex s Test-And-Set

More information

IV. Process Synchronisation

IV. Process Synchronisation IV. Process Synchronisation Operating Systems Stefan Klinger Database & Information Systems Group University of Konstanz Summer Term 2009 Background Multiprogramming Multiple processes are executed asynchronously.

More information

EECS 482 Introduction to Operating Systems

EECS 482 Introduction to Operating Systems EECS 482 Introduction to Operating Systems Winter 2018 Harsha V. Madhyastha Recap Multi-threaded code with monitors: Locks for mutual exclusion Condition variables for ordering constraints Every thread

More information

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

POSIX Threads: a first step toward parallel programming. George Bosilca POSIX Threads: a first step toward parallel programming George Bosilca bosilca@icl.utk.edu Process vs. Thread A process is a collection of virtual memory space, code, data, and system resources. A thread

More information

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

Background. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling. Background The Critical-Section Problem Background Race Conditions Solution Criteria to Critical-Section Problem Peterson s (Software) Solution Concurrent access to shared data may result in data inconsistency

More information

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

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

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

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles Operating Systems: Internals and Design Principles Chapter 5 Concurrency: Mutual Exclusion and Synchronization Seventh Edition By William Stallings Designing correct routines for controlling concurrent

More information

Last Class: Synchronization

Last Class: Synchronization Last Class: Synchronization Synchronization primitives are required to ensure that only one thread executes in a critical section at a time. Concurrent programs Low-level atomic operations (hardware) load/store

More information

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

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Operating Systems Lecture 4 - Concurrency and Synchronization Adrien Krähenbühl Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Mutual exclusion Hardware solutions Semaphores IPC: Message passing

More information

CPS 110 Midterm. Spring 2011

CPS 110 Midterm. Spring 2011 CPS 110 Midterm Spring 2011 Ola! Greetings from Puerto Rico, where the air is warm and salty and the mojitos are cold and sweet. Please answer all questions for a total of 200 points. Keep it clear and

More information

Implementing Mutual Exclusion. Sarah Diesburg Operating Systems CS 3430

Implementing Mutual Exclusion. Sarah Diesburg Operating Systems CS 3430 Implementing Mutual Exclusion Sarah Diesburg Operating Systems CS 3430 From the Previous Lecture The too much milk example shows that writing concurrent programs directly with load and store instructions

More information

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10 MULTITHREADING AND SYNCHRONIZATION CS124 Operating Systems Fall 2017-2018, Lecture 10 2 Critical Sections Race conditions can be avoided by preventing multiple control paths from accessing shared state

More information

Introduction to OS Synchronization MOS 2.3

Introduction to OS Synchronization MOS 2.3 Introduction to OS Synchronization MOS 2.3 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Challenge How can we help processes synchronize with each other? E.g., how

More information

Chap. 3. Input/Output

Chap. 3. Input/Output Chap. 3. Input/Output 17 janvier 07 3.1 Principles of I/O hardware 3.2 Principles of I/O software 3.3 Deadlocks [3.4 Overview of IO in Minix 3] [3.5 Block Devices in Minix 3] [3.6 RAM Disks] 3.7 Disks

More information

Dealing with Issues for Interprocess Communication

Dealing with Issues for Interprocess Communication Dealing with Issues for Interprocess Communication Ref Section 2.3 Tanenbaum 7.1 Overview Processes frequently need to communicate with other processes. In a shell pipe the o/p of one process is passed

More information

MODERN OPERATING SYSTEMS

MODERN OPERATING SYSTEMS MODERN OPERATING SYSTEMS THIRD EDITION ANDREW S. TANENBAUM Vrije Universiteit Amsterdam, The Netherlands PEARSON Prentice Hall UPPER SADDLE RIVER, NEW JERSEY 07458 PREFACE xxiv 1 INTRODUCTION 1 1.1 WHAT

More information

Process Synchronization

Process Synchronization CSC 4103 - Operating Systems Spring 2007 Lecture - VI Process Synchronization Tevfik Koşar Louisiana State University February 6 th, 2007 1 Roadmap Process Synchronization The Critical-Section Problem

More information

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

CS 333 Introduction to Operating Systems. Class 4 Concurrent Programming and Synchronization Primitives CS 333 Introduction to Operating Systems Class 4 Concurrent Programming and Synchronization Primitives Jonathan Walpole Computer Science Portland State University 1 Concurrent programming Assumptions:

More information

Chapter 2 - Processes and Threads

Chapter 2 - Processes and Threads Chapter 2 - Processes and Threads Luis Tarrataca luis.tarrataca@gmail.com CEFET-RJ L. Tarrataca Chapter 2 - Processes and Threads 1 / 274 1 Motivation 2 Processes The process model Process Termination

More information

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

Threads. Concurrency. What it is. Lecture Notes Week 2. Figure 1: Multi-Threading. Figure 2: Multi-Threading Threads Figure 1: Multi-Threading Figure 2: Multi-Threading Concurrency What it is 1. Two or more threads of control access a shared resource. Scheduler operation must be taken into account fetch-decode-execute-check

More information

Midterm Exam. October 20th, Thursday NSC

Midterm Exam. October 20th, Thursday NSC CSE 421/521 - Operating Systems Fall 2011 Lecture - XIV Midterm Review Tevfik Koşar University at Buffalo October 18 th, 2011 1 Midterm Exam October 20th, Thursday 9:30am-10:50am @215 NSC Chapters included

More information

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Chapter 5 Concurrency: Mutual Exclusion and Synchronization Seventh Edition By William Stallings Designing correct routines for controlling concurrent

More information

Locks. Dongkun Shin, SKKU

Locks. Dongkun Shin, SKKU Locks 1 Locks: The Basic Idea To implement a critical section A lock variable must be declared A lock variable holds the state of the lock Available (unlocked, free) Acquired (locked, held) Exactly one

More information

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

Background. Old Producer Process Code. Improving the Bounded Buffer. Old Consumer Process Code Old Producer Process Code Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Our

More information

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

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; } Semaphore Semaphore S integer variable Two standard operations modify S: wait() and signal() Originally called P() and V() Can only be accessed via two indivisible (atomic) operations wait (S) { while

More information

1995 Paper 10 Question 7

1995 Paper 10 Question 7 995 Paper 0 Question 7 Why are multiple buffers often used between producing and consuming processes? Describe the operation of a semaphore. What is the difference between a counting semaphore and a binary

More information

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

Process Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212 Operating Systems Spring 2009-2010 Outline Process Synchronisation (contd.) 1 Process Synchronisation (contd.) 2 Announcements Presentations: will be held on last teaching week during lectures make a 20-minute

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 1018 L11 Synchronization Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel feedback queue:

More information

Synchronization Principles

Synchronization Principles Synchronization Principles Gordon College Stephen Brinton The Problem with Concurrency Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms

More information

Synchronising Threads

Synchronising Threads Synchronising Threads David Chisnall March 1, 2011 First Rule for Maintainable Concurrent Code No data may be both mutable and aliased Harder Problems Data is shared and mutable Access to it must be protected

More information

Synchronization for Concurrent Tasks

Synchronization for Concurrent Tasks Synchronization for Concurrent Tasks Minsoo Ryu Department of Computer Science and Engineering 2 1 Race Condition and Critical Section Page X 2 Algorithmic Approaches Page X 3 Hardware Support Page X 4

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 11 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel Feedback Queue: Q0, Q1,

More information

Mutex Implementation

Mutex Implementation COS 318: Operating Systems Mutex Implementation Jaswinder Pal Singh Computer Science Department Princeton University (http://www.cs.princeton.edu/courses/cos318/) Revisit Mutual Exclusion (Mutex) u Critical

More information

Process Synchronization (Part I)

Process Synchronization (Part I) Process Synchronization (Part I) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) Process Synchronization 1393/7/14 1 / 44 Motivation

More information

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

Threads and Critical Sections. Otto J. Anshus, Thomas Plagemann, Tore Brox-Larsen, Kai Li Threads and Critical Sections Otto J. Anshus, Thomas Plagemann, Tore Brox-Larsen, Kai Li Thread and Address Space Thread A sequential execution stream within a process (also called lightweight process)

More information

Threading and Synchronization. Fahd Albinali

Threading and Synchronization. Fahd Albinali Threading and Synchronization Fahd Albinali Parallelism Parallelism and Pseudoparallelism Why parallelize? Finding parallelism Advantages: better load balancing, better scalability Disadvantages: process/thread

More information

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

CSE Traditional Operating Systems deal with typical system software designed to be: CSE 6431 Traditional Operating Systems deal with typical system software designed to be: general purpose running on single processor machines Advanced Operating Systems are designed for either a special

More information

Today: Synchronization. Recap: Synchronization

Today: Synchronization. Recap: Synchronization Today: Synchronization Synchronization Mutual exclusion Critical sections Example: Too Much Milk Locks Synchronization primitives are required to ensure that only one thread executes in a critical section

More information

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ! Last Class: CPU Scheduling! Scheduling Algorithms: FCFS Round Robin SJF Multilevel Feedback Queues Lottery Scheduling Review questions: How does each work? Advantages? Disadvantages? Lecture 7, page 1

More information

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

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings Chapter 6 Concurrency: Deadlock and Starvation Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall Deadlock

More information

Chapter 1 Introduction

Chapter 1 Introduction MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 1 Introduction What Is An Operating System (1) A modern computer consists of: One or more processors Main memory Disks Printers Various

More information

CS 450 Exam 2 Mon. 4/11/2016

CS 450 Exam 2 Mon. 4/11/2016 CS 450 Exam 2 Mon. 4/11/2016 Name: Rules and Hints You may use one handwritten 8.5 11 cheat sheet (front and back). This is the only additional resource you may consult during this exam. No calculators.

More information

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

Lecture Outline. CS 5523 Operating Systems: Concurrency and Synchronization. a = 0; b = 0; // Initial state Thread 1. Objectives. CS 5523 Operating Systems: Concurrency and Synchronization Thank Dr. Dakai Zhu and Dr. Palden Lama for providing their slides. Lecture Outline Problems with concurrent access to shared data Ø Race condition

More information

Concurrency: a crash course

Concurrency: a crash course Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Concurrency: a crash course Concurrent computing Applications designed as a collection of computational units that may execute

More information

Concurrent & Distributed Systems Supervision Exercises

Concurrent & Distributed Systems Supervision Exercises Concurrent & Distributed Systems Supervision Exercises Stephen Kell Stephen.Kell@cl.cam.ac.uk November 9, 2009 These exercises are intended to cover all the main points of understanding in the lecture

More information

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

Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux 1 Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux Jhuyeong Jhin and Injung Hwang Race Condition & Critical Region 2 Race Condition Result may change according

More information

High-level Synchronization

High-level Synchronization Recap of Last Class High-level Synchronization CS 256/456 Dept. of Computer Science, University of Rochester Concurrent access to shared data may result in data inconsistency race condition. The Critical-Section

More information

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Semaphores Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3052: Introduction to Operating Systems, Fall 2017, Jinkyu Jeong (jinkyu@skku.edu) Synchronization

More information

Frequently asked questions from the previous class survey

Frequently asked questions from the previous class survey CS 370: OPERATING SYSTEMS [DEADLOCKS] Shrideep Pallickara Computer Science Colorado State University L16.1 Frequently asked questions from the previous class survey Exponential Moving Average Is the α

More information