7: Interprocess Communication

Size: px
Start display at page:

Download "7: Interprocess Communication"

Transcription

1 7: Interprocess Communication Mark Handley Interprocess Communication Processes frequently need to communicate to perform tasks. Shared memory. Shared files. Message passing. Whenever processes communicate, the relative timing of communication can become a factor in the outcome. Such timing dependencies are normally bad. Called a race condition. 1

2 Ornamental Garden Problem Garden open to the public Enter through either one of two turnstiles Computer to count number of visitors Garden East Turnstile Count West Turnstile Each turnstile implemented by a Java thread Ornamental Garden: Counter class class Counter { int value_=0; public void increment() { int tmp = value_; //read ++tmp; //add one value_=tmp; //write 2

3 Ornamental Garden: Turnstile class class Turnstile extends Thread { Counter people_; Turnstile(Counter c) { people_ = c; public void run() { while(true) people_.increment(); Ornamental Garden: Program Counter people_ = new Counter(); Turnstile west_ = new Turnstile(people_); Turnstile east_ = new Turnstile(people_); west_.start(); east_.start(); What will happen? Demo: Ornamental Garden 3

4 Interference East: value:2 e.tmp=_value; tmp:2 e.tmp++; tmp:3 West: w.tmp = _value; tmp:2 w.tmp++; tmp:3 _value = tmp; value:3 _value = tmp; value:3 _value started with 2, got incremented twice, and ended with 3. This is an example of a destructive update. Interference Destructive updates caused by arbitrary interleaving of read and write actions on shared variables is called interference Avoid interference by making access to critical sections mutually exclusive 4

5 Critical Section A critical section or critical region is a sequence of actions that must be executed by at most one process or thread at a time Can be found by searching for sections of code that access or update variables or objects that are shared by concurrent processes. Mutual Exclusion 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 5

6 Mutual Exclusion Mutual exclusion using critical regions Critical Sections in Java Synchronised methods implement mutual exclusion Implicitly locking objects: class Counter { int value_=0; public synchronized void increment() { int tmp = _value; //read ++tmp; //add one _value = tmp; //write Only one thread can be in increment() at a time. 6

7 Race Conditions Print Spooler Two processes want to access shared file at the same time. Strict Alternation Process 1: while (TRUE) { while (turn!=0) {/*Loop*/ critical_region(); turn = 1; noncritical_region(); Process 2: while (TRUE) { while (turn!=1) {/*Loop*/ critical_region(); turn = 0; noncritical_region(); Processes alternate, each busy-waiting while the other is in it s critical region. 7

8 Peterson s Algorithm Mutual Exclusion with Busy Waiting #define N 2 /* two processes */ int turn; /* whose turn it is? */ int interested[n]; /* all initially FALSE (0) */ void enter_region(int process) { /* process is 0 or 1 */ int otherproc = 1 - process; /* the no. of the other process */ interested[process] = TRUE; /* show we re interested*/ turn = process; /* set flag */ while (turn == process && interested[otherpro] == TRUE) { /*LOOP*/ void leave_region(int process { /* process: who is leaving */ interested[process] = FALSE; /* indicate no longer in critical region* Mutual Exclusion with Busy Waiting: Help from the Hardware TSL Instruction: Test and Set Lock TSL REGISTER, LOCK 1. Reads contents of memory address LOCK into REGISTER. 2. Writes a non-zero value to LOCK. TSL is atomic, and locks the memory bus while executing so no other CPU can access the LOCK memory while the TSL instruction is in progress. Intel x86 version is called BTS (Bit Test and Set) 8

9 Mutual Exclusion with Busy Waiting: Usage of TSL enter_region: TSL REGISTER,LOCK //copy lock to register and set lock to 1 CMP REGISTER, 0 //test if copied value was zero JNE enter_region //if not, loop and try again RET //return to caller, and enter critical region leave_region: MOVE LOCK, 0 RET //store a zero in lock Busy Waiting Peterson s algorithm and TSL both correctly implement mutual exclusion, at the expense of busy-waiting. Wasteful of CPU Can have unexpected consequences. Priority Inversion: High priority task busy waits on lock. Low priority task in critical section never gets the CPU, so can never leave the critical section. 9

10 Sleep/Wakeup Simple way to avoid busy waiting: sleep() causes the caller to block until woken up by a call be wakeup() wakeup(int process) causes another sleeping process to be woken up. Producer/Consumer Problem Two processes: a producer and a consumer. Share a common fixed-size buffer. Producer Consumer Producer sleeps if no space in buffer. Consumer wakes it up when there s space. Consumer sleeps if no data in buffer. Producer wakes it up when there s data. 10

11 Producer/Consumer with Sleep/Wakeup (Fatally flawed due to Race Condition) #define N 100 /* no. of slots in buffer */ int count = 0; /* no. of items in buffer */ void producer() { while (TRUE) { int item = produce_item(); /* generate next item */ if (count == N) sleep(); /* go to sleep if buffer is full */ insert_item(item); /* store item in buffer */ count++; /* increment count of items in buffer */ if (count == 1) wakeup(consumer); /* if buffer was empty, wake consumer */ Producer will never call wakeup again Eventually buffer fills and both processes sleep forever Interrupt Wakeup occurs, called, Scheduler but consumer Switches not Thread sleeping! void consumer() { Consumer now sleeps while (TRUE) { if (count == 0) sleep(); /* sleep if nothing in buffer */ item = remove_item(); /* take item from buffer */ count--; /* decrement count of items in buffer*/ if (count == N-1) wakeup(producer); /* if buffer was full, wake producer */ consume_item(item); Summary Inter-process communication Potential for race conditions Destructive interference. Need for mutual exclusion in critical sections. Synchronize in Java Mutual Exclusion Alternation Peterson s Algorithm TSL Sleep/Wakeup Next: potential solutions to Producer/Consumer problem. 11

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

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

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

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

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

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

Synchronization. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Synchronization. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University Synchronization Design, Spring 2011 Department of Computer Science Synchronization Basic problem: Threads are concurrently accessing shared variables The access should be controlled for predictable result.

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 11: Semaphores I" Brian Logan School of Computer Science bsl@cs.nott.ac.uk Outline of this lecture" problems with Peterson s algorithm semaphores implementing semaphores

More information

Concurrency and Synchronisation. Leonid Ryzhyk

Concurrency and Synchronisation. Leonid Ryzhyk Concurrency and Synchronisation Leonid Ryzhyk Textbook Sections 2.3 & 2.5 2 Concurrency in operating systems Inter-process communication web server SQL request DB Intra-process communication worker thread

More information

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

OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL. Chap. 2.2 Interprocess Communication 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,

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

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

Operating Systems. User OS. Kernel & Device Drivers. Interface Programs. Interprocess Communication (IPC) Operating Systems User OS Kernel & Device Drivers Interface Programs Interprocess Communication (IPC) Brian Mitchell (bmitchel@mcs.drexel.edu) - Operating Systems 1 Interprocess Communication Shared Memory

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

CS Operating Systems

CS Operating Systems CS 4500 - Operating Systems Module 4: The Producer-Consumer Problem and Solution Methods Stanley Wileman Department of Computer Science University of Nebraska at Omaha Omaha, NE 68182-0500, USA June 3,

More information

CS Operating Systems

CS Operating Systems CS 4500 - Operating Systems Module 4: The Producer-Consumer Problem and Solution Methods Stanley Wileman Department of Computer Science University of Nebraska at Omaha Omaha, NE 68182-0500, USA June 3,

More information

Operating Systems. OPS Processes

Operating Systems. OPS Processes Handout Introduction Operating Systems OPS Processes These notes were originally written using (Tanenbaum, 1992) but later editions (Tanenbaum, 2001; 2008) contain the same information. Introduction to

More information

Processes. Introduction to Processes. The Process Model

Processes. Introduction to Processes. The Process Model Processes Introduction to Processes The most central concept in any operating system is the process: an abstraction of a running program. Consider a user PC. When the system is booted, many processes are

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

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

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

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 4: Atomic Actions Natasha Alechina School of Computer Science nza@cs.nott.ac.uk Outline of the lecture process execution fine-grained atomic actions using fine-grained

More information

Process Synchronization

Process Synchronization Process Synchronization Concurrent access to shared data may result in data inconsistency Multiple threads in a single process Maintaining data consistency requires mechanisms to ensure the orderly execution

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

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

Operating Systems. David Vernon. Copyright 2007 David Vernon (www.vernon.eu)

Operating Systems. David Vernon. Copyright 2007 David Vernon (www.vernon.eu) Operating Systems David Vernon Course Overview Key objective is to introduce the concept of operating systems (OS) The need for operating systems Understand design choices, design tradeoffs, and implications

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

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

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

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

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

Shared Objects & Mutual Exclusion

Shared Objects & Mutual Exclusion Feb. 08, 2012 Concurrent Execution Concepts Process interference Mutual exclusion Models Model checking for interference Modeling mutual exclusion Practice Multithreaded Java programs Thread interference

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

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

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

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

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack What is it? Recap: Thread Independent flow of control What does it need (thread private)? Stack What for? Lightweight programming construct for concurrent activities How to implement? Kernel thread vs.

More information

1. Basic Synchronization Principles What is the reason for synchronization

1. Basic Synchronization Principles What is the reason for synchronization 1. Basic Synchronization Principles What is the reason for synchronization 1.1. Race Conditions Processes frequently need to communicate with other processes. Situations like this, where two or more processes

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS

More information

Synchronization: semaphores and some more stuff. Operating Systems, Spring 2018, I. Dinur, D. Hendler and R. Iakobashvili

Synchronization: semaphores and some more stuff. Operating Systems, Spring 2018, I. Dinur, D. Hendler and R. Iakobashvili Synchronization: semaphores and some more stuff 1 What's wrong with busy waiting? The mutual exclusion algorithms we saw used busy-waiting. What s wrong with that? Doesn't make sense for uni-processor

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

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

Synchronization I. Jo, Heeseung

Synchronization I. Jo, Heeseung Synchronization I Jo, Heeseung Today's Topics Synchronization problem Locks 2 Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Also, to coordinate

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

Synchronization. Disclaimer: some slides are adopted from the book authors slides with permission 1

Synchronization. Disclaimer: some slides are adopted from the book authors slides with permission 1 Synchronization Disclaimer: some slides are adopted from the book authors slides with permission 1 What is it? Recap: Thread Independent flow of control What does it need (thread private)? Stack What for?

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

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

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

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

CSCI 5828: Foundations of Software Engineering

CSCI 5828: Foundations of Software Engineering CSCI 5828: Foundations of Software Engineering Lecture 12: Concurrent Execution Slides created by Magee and Kramer for the Concurrency textbook 1 Chapter 4 Shared Objects & Mutual Exclusion Concurrency:

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

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

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

CENG334 Introduction to Operating Systems

CENG334 Introduction to Operating Systems CENG334 Introduction to Operating Systems Semaphores Topics: Need for higher-level synchronization primitives Semaphores and their implementation The Producer/Consumer problem and its solution with semaphores

More information

The University of Texas at Arlington

The University of Texas at Arlington The University of Texas at Arlington Lecture 6: Threading and Parallel Programming Constraints CSE 5343/4342 Embedded Systems II Based heavily on slides by Dr. Roger Walker More Task Decomposition: Dependence

More information

The University of Texas at Arlington

The University of Texas at Arlington The University of Texas at Arlington Lecture 10: Threading and Parallel Programming Constraints CSE 5343/4342 Embedded d Systems II Objectives: Lab 3: Windows Threads (win32 threading API) Convert serial

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

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

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

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6. Part Three - Process Coordination Chapter 6: Synchronization 6.1 Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure

More information

Q1. From post-it note. Question asked after Prev. Lecture. thread life-cycle in Java. Q2. Concurrency and parallelism. Definitions

Q1. From post-it note. Question asked after Prev. Lecture. thread life-cycle in Java. Q2. Concurrency and parallelism. Definitions Question asked after Prev. Lecture Q1. From post-it note If JVM is running inside one OS process, are the threads of a Java program truly parallel? Answer The threads will be time-shared. At any point,

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Chapter 6: Synchronization 6.1 Background 6.2 The Critical-Section Problem 6.3 Peterson s Solution 6.4 Synchronization Hardware 6.5 Mutex Locks 6.6 Semaphores 6.7 Classic

More information

CS420: Operating Systems. Process Synchronization

CS420: Operating Systems. Process Synchronization Process Synchronization James Moscola Department of Engineering & Computer Science York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne Background

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

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 Process creation in UNIX All processes have a unique process id getpid(),

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 What does a typical thread API look

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

Dept. of CSE, York Univ. 1

Dept. of CSE, York Univ. 1 EECS 3221.3 Operating System Fundamentals No.5 Process Synchronization(1) Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University Background: cooperating processes with shared

More information

SOLUTIONS FOR THE SECOND 4330/6310 QUIZ. Jehan-François Pâris Spring 2015

SOLUTIONS FOR THE SECOND 4330/6310 QUIZ. Jehan-François Pâris Spring 2015 SOLUTIONS FOR THE SECOND 4330/6310 QUIZ Jehan-François Pâris Spring 2015 First Question Consider the following solution to the mutual exclusion problem and explain when it fails (5 points) and what happens

More information

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

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Synchronization I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Synchronization problem Locks 2 Synchronization Threads cooperate

More information

Process Management And Synchronization

Process Management And Synchronization Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the

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

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs CSE 451: Operating Systems Winter 2005 Lecture 7 Synchronization Steve Gribble Synchronization Threads cooperate in multithreaded programs to share resources, access shared data structures e.g., threads

More information

Synchronization in Concurrent Programming. Amit Gupta

Synchronization in Concurrent Programming. Amit Gupta Synchronization in Concurrent Programming Amit Gupta Announcements Project 1 grades are out on blackboard. Detailed Grade sheets to be distributed after class. Project 2 grades should be out by next Thursday.

More information

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

COMPUTER SCIENCE 4500 OPERATING SYSTEMS Last update: 1/6/2017 COMPUTER SCIENCE 4500 OPERATING SYSTEMS 2017 Stanley Wileman Module 3: The Process Model, Threads, and Interprocess Communication In This Module 2! The Process Model! Process States!

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

Interprocess Communication By: Kaushik Vaghani

Interprocess Communication By: Kaushik Vaghani Interprocess Communication By: Kaushik Vaghani Background Race Condition: A situation where several processes access and manipulate the same data concurrently and the outcome of execution depends on the

More information

G52CON: Concepts of Concurrency

G52CON: Concepts of Concurrency G52CON: Concepts of Concurrency Lecture 6: Algorithms for Mutual Natasha Alechina School of Computer Science nza@cs.nott.ac.uk Outline of this lecture mutual exclusion with standard instructions example:

More information

Computer Science 4500 Operating Systems

Computer Science 4500 Operating Systems Computer Science 4500 Module 3 The Process Model, Threads, and Interprocess Communication Updated 7/21/2014 Slide 1 In This Module The Process Model Process States Threads Interrupts, Traps and Signals

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

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

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

Mutual Exclusion and Synchronization

Mutual Exclusion and Synchronization Mutual Exclusion and Synchronization Concurrency Defined Single processor multiprogramming system Interleaving of processes Multiprocessor systems Processes run in parallel on different processors Interleaving

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

Chapter 5 Asynchronous Concurrent Execution

Chapter 5 Asynchronous Concurrent Execution Chapter 5 Asynchronous Concurrent Execution Outline 5.1 Introduction 5.2 Mutual Exclusion 5.2.1 Java Multithreading Case Study 5.2.2 Critical Sections 5.2.3 Mutual Exclusion Primitives 5.3 Implementing

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

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

Week 7. Concurrent Programming: Thread Synchronization. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Week 7. Concurrent Programming: Thread Synchronization. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Week 7 Concurrent Programming: Thread Synchronization CS 180 Sunil Prabhakar Department of Computer Science Purdue University Announcements Exam 1 tonight 6:30 pm - 7:30 pm MTHW 210 2 Outcomes Understand

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

CSCI 447 Operating Systems Filip Jagodzinski

CSCI 447 Operating Systems Filip Jagodzinski Filip Jagodzinski Announcements Reading Task Should take 30 minutes-ish maximum Homework 2 Book questions including two custom ones will be posted to the course website today Programming tasks will be

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 7: Synchronization Administrivia Homework 1 Due today by the end of day Hopefully you have started on project 1 by now? Kernel-level threads (preemptable

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

Midterm on next week Tuesday May 4. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9

Midterm on next week Tuesday May 4. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9 CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce

More information

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

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS Name: Student Number: SOLUTIONS ENGR 3950U / CSCI 3020U (Operating Systems) Quiz on Process Synchronization November 13, 2012, Duration: 40 Minutes (10 questions and 8 pages, 45 Marks) Instructor: Dr.

More information

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 The Process Concept 2 The Process Concept Process a program in execution

More information

Last class: Today: CPU Scheduling. Start synchronization

Last class: Today: CPU Scheduling. Start synchronization Last class: CPU Scheduling Today: Start synchronization Synchronization Processes (threads) share resources. How do processes share resources? How do threads share resources? It is important to coordinate

More information

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions CMSC 330: Organization of Programming Languages Multithreaded Programming Patterns in Java CMSC 330 2 Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to

More information

Lesson 6: Process Synchronization

Lesson 6: Process Synchronization Lesson 6: Process Synchronization Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization

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

Process Synchronization

Process Synchronization TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Process Synchronization [SGG7] Chapter 6 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin

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

Process & Thread Management II. Queues. Sleep() and Sleep Queues CIS 657

Process & Thread Management II. Queues. Sleep() and Sleep Queues CIS 657 Process & Thread Management II CIS 657 Queues Run queues: hold threads ready to execute Not a single ready queue; 64 queues All threads in same queue are treated as same priority Sleep queues: hold threads

More information