# Synchronization Classic Problems

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 CS 4410 Operating Systems Synchronization Classic Problems Summer 2013 Cornell University 1

2 Today What practical problems can we solve with semaphores? Bounded-Buffer Problem Producer-Consumer Problem 2

3 Producer-Consumer Problem Arises when two or more threads communicate with each other. And, some threads produce data and other threads consume this data. Real example: Production line 3

4 Producer-Consumer Problem Start by imagining an unbounded (infinite) buffer Producer process writes data to buffer Writes to In and moves rightwards Consumer process reads data from buffer Reads from Out and moves rightwards Should not try to consume if there is no data Out In 4

5 Producer-Consumer Problem Bounded buffer: size N Access entry 0 N-1, then wrap around to 0 again Producer process writes data to buffer Must not write more than N items more than consumer ate Consumer process reads data from buffer Should not try to consume if there is no data 0 1 N-1 In Out 5

6 Producer-Consumer Problem Multiple producer-threads. Multiple consumer-threads. One bounded buffer with N entries. All threads modify the same buffer. Requirements: No production when all N entries are full. No consumption when no entry is full. Only one thread should modify the buffer at any time. 6

7 Producer-Consumer Problem Solving with semaphores: We ll use counters to track how much data is in the buffer One counter counts as we add data and stops a producer if there are N objects in the buffer. A second counter counts as we remove data and stops a consumer if there are 0 in the buffer. Idea: since general semaphores can count for us, we don t need a separate counter variable. We'll use a mutex to protect the update of the buffer ( In and Out pointers). 7

8 Producer-Consumer Problem Shared pointers: In, Out Shared Semaphores: mutex, empty, full; mutex = 1; /* for mutual exclusion*/ empty = N; /* number empty buf entries */ full = 0; /* number full buf entries */ do { Producer do { Consumer //produce item //update In //consume item //update Out } while (true); } while (true); 8

9 Producer-Consumer Problem Shared pointers: In, Out Shared Semaphores: mutex, empty, full; mutex = 1; /* for mutual exclusion*/ empty = N; /* number empty buf entries */ full = 0; /* number full buf entries */ do { Producer wait(empty); do { Consumer wait(full); //produce item //update In signal(full); } while (true); //consume item //update Out signal(empty); } while (true); 9

10 Producer-Consumer Problem Shared pointers: In, Out Shared Semaphores: mutex, empty, full; mutex = 1; /* for mutual exclusion*/ empty = N; /* number empty buf entries */ full = 0; /* number full buf entries */ Producer do { wait(empty); wait(mutex); //produce item //update In signal(mutex); signal(full); } while (true); do { Consumer wait(full); wait(mutex); //consume item //update Out signal(mutex); signal(empty); } while (true); 10

11 Readers and Writers In this problem, threads share data that some threads read and other threads write. Goal: allow multiple concurrent readers but only a single writer at a time, and if a writer is active, readers wait for it to finish. 11

12 Readers-Writers Problem Access to a database A reader is a thread that needs to look at the database but won t change it. A writer is a thread that modifies the database. Making an airline reservation When you browse to look at flight schedules the web site is acting as a reader on your behalf. When you reserve a seat, the web site has to write into the database to make the reservation. 12

13 Readers-Writers Problem Many reader-threads. Many writer-threads. One piece of data. Multiple threads try to access that data. Requirements: Multiple readers may access the data at the same time. If a writer accesses the data, no other thread may access the data. What happens when multiple readers and one writer are waiting to access the data? 13

14 Readers-Writers Problem mutex = Semaphore(1) wrt = Semaphore(1) readcount = 0; Reader do{ Writer do{ /*reading is performed*/ /*writing is performed*/ }while(true) }while(true) 14

15 Readers-Writers Problem mutex = Semaphore(1) wrt = Semaphore(1) readcount = 0; Reader do{ Writer do{ wait(wrt); /*writing is performed*/ signal(wrt); }while(true) wait(wrt); /*reading is performed*/ signal(wrt); }while(true) 15

16 Readers-Writers Problem mutex = Semaphore(1) wrt = Semaphore(1) readcount = 0; Writer do{ wait(wrt); /*writing is performed*/ signal(wrt); }while(true) Reader do{ wait(mutex); readcount++; if (reardcount == 1) wait(wrt); signal(mutex); /*reading is performed*/ wait(mutex); readcount--; if (readcount == 0) signal(wrt); signal(mutex); }while(true) 16

17 Readers-Writers Notes If there is a writer First reader blocks on wrl Other readers block on mutex Once a reader is active, all readers get to go through Which reader gets in first? The last reader to exit signals a writer If no writer, then readers can continue If readers and writers are waiting on wrl, and writer exits Who gets to go in first? Why doesn t a writer need to use mutex? Is the previous solution fair? Readers can starve writers! Building a fair solution is tricky! 17

18 Today Which practical problems can we solve with semaphores? Producers-Consumers Problem Readers-Writers Problem

### Process Coordination

Process Coordination Why is it needed? Processes may need to share data More than one process reading/writing the same data (a shared file, a database record, ) Output of one process being used by another

### Synchronization Basic Problem:

Synchronization Synchronization Basic Problem: If two concurrent processes are accessing a shared variable, and that variable is read, modified, and written by those processes, then the variable must be

### COP 4225 Advanced Unix Programming. Synchronization. Chi Zhang

COP 4225 Advanced Unix Programming Synchronization Chi Zhang czhang@cs.fiu.edu 1 Cooperating Processes Independent process cannot affect or be affected by the execution of another process. Cooperating

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

Synchronization Peter J. Denning CS471/CS571 Copyright 2001, by Peter Denning What is synchronization? Requirement that one process stop to wait to pass a point until another process sends a signal. The

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

Module 6: Process Synchronization Background Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization

### Chapter 7: Process Synchronization. Background. Illustration

Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris

### Process Synchronization

Chapter 7 Process Synchronization 1 Chapter s Content Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors 2 Background

### CS370 Operating Systems

CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 12 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ 2 Mutex vs Semaphore Mutex is binary,

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

### CSE 120. Fall Lecture 6: Semaphores. Keith Marzullo

CSE 120 Principles of Operating Systems Fall 2007 Lecture 6: Semaphores Keith Marzullo Announcements Homework #2 out Homework #1 almost graded... Discussion session on Wednesday will entertain questions

### Semaphores (by Dijkstra)

CSCI 4401 Principles of Operating Systems I Process Synchronization II: Classic Problems Vassil Roussev vassil@cs.uno.edu Semaphores (by Dijkstra) A higher-level way of doing synchronization between threads/processes

### CSE Opera,ng System Principles

CSE 30341 Opera,ng System Principles Synchroniza2on Overview Background The Cri,cal-Sec,on Problem Peterson s Solu,on Synchroniza,on Hardware Mutex Locks Semaphores Classic Problems of Synchroniza,on Monitors

### Process Synchronization

Process Synchronization Mandar Mitra Indian Statistical Institute M. Mitra (ISI) Process Synchronization 1 / 28 Cooperating processes Reference: Section 4.4. Cooperating process: shares data with other

### 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

### CS3733: Operating Systems

Outline CS3733: Operating Systems Topics: Synchronization, Critical Sections and Semaphores (SGG Chapter 6) Instructor: Dr. Tongping Liu 1 Memory Model of Multithreaded Programs Synchronization for coordinated

### 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

### 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

### OS Process Synchronization!

OS Process Synchronization! Race Conditions! The Critical Section Problem! Synchronization Hardware! Semaphores! Classical Problems of Synchronization! Synchronization HW Assignment! 3.1! Concurrent Access

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

CS341: Operating System Mid Semester Model Solution Uploaded Semaphore ADT: wait(), signal() Lect23: 30 th Sept 2014 Dr. A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati Classical

### 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

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

### 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

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

"#! \$ %! *+ &' & "-/ &+, :/!! &+ 8/!.!"!! > &, < &+ 7!! "-/ :/= +. :/= 0 0/ 7!@?+ C (" & + A &B' 7! G' 3/ 0"=' 7> H 0 4 0! &D E.! 0 n I"2 &+ % &B' 0!!! n 1 + counter J " &B' & K n

### 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

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

Concurrency pros and cons Con Programming Problems OS Spring 2011 Concurrency is good for users One of the reasons for multiprogramming Working on the same problem, simultaneous execution of programs,

### CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems Fall 2017 Lecture 7: Semaphores and Monitors Ryan Huang Higher-Level Synchronization We looked at using locks to provide mutual exclusion Locks work, but they have

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

Race Condition Synchronization CSCI 315 Operating Systems Design Department of Computer Science A race occurs when the correctness of a program depends on one thread reaching point x in its control flow

### Chapter 5: Process Synchronization

Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013! Chapter 5: Process Synchronization Background" The Critical-Section Problem" Petersons Solution" Synchronization Hardware" Mutex

### Synchronization COMPSCI 386

Synchronization COMPSCI 386 Obvious? // push an item onto the stack while (top == SIZE) ; stack[top++] = item; // pop an item off the stack while (top == 0) ; item = stack[top--]; PRODUCER CONSUMER Suppose

### Process Co-ordination OPERATING SYSTEMS

OPERATING SYSTEMS Prescribed Text Book Operating System Principles, Seventh Edition By Abraham Silberschatz, Peter Baer Galvin and Greg Gagne 1 PROCESS - CONCEPT Processes executing concurrently in the

### 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

### CS 3723 Operating Systems: Final Review

CS 3723 Operating Systems: Final Review Instructor: Dr. Tongping Liu Lecture Outline High-level synchronization structure: Monitor Pthread mutex Conditional variables Barrier Threading Issues 1 2 Monitors

### Synchronization. Dr. Yingwu Zhu

Synchronization Dr. Yingwu Zhu Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Threads accessing a memory cache in a Web server To coordinate

### 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

### 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

### CHAPTER 6: PROCESS SYNCHRONIZATION

CHAPTER 6: PROCESS SYNCHRONIZATION The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. TOPICS Background

### 2 Programs and processes

B16 SOFTWARE ENGINEERING: OPERATING SYSTEMS 9 2 Programs and processes A program is its code; a process is an instance of a program, together with its state: its data. There may be several copies of the

### 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

### 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

### Process Synchronization

Process Synchronization Chapter 6 2015 Prof. Amr El-Kadi Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly

### Synchronization Spinlocks - Semaphores

CS 4410 Operating Systems Synchronization Spinlocks - Semaphores Summer 2013 Cornell University 1 Today How can I synchronize the execution of multiple threads of the same process? Example Race condition

### Process Synchronization

Process Synchronization Concurrent access to shared data in the data section of a multi-thread process, in the shared memory of multiple processes, or in a shared file Although every example in this chapter

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

Lecture Topics Today: Concurrency (Stallings, chapter 5.1-5.4, 5.7) Next: Exam #1 1 Announcements Self-Study Exercise #5 Project #3 (due 9/28) Project #4 (due 10/12) 2 Exam #1 Tuesday, 10/3 during lecture

### CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CS 471 Operating Systems Yue Cheng George Mason University Fall 2017 1 Review: Sync Terminology Worksheet 2 Review: Semaphores 3 Semaphores o Motivation: Avoid busy waiting by blocking a process execution

### 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

### Chapter 6 Synchronization

Chapter 6 Synchronization Da-Wei Chang CSIE.NCKU Source: Abraham Silberschatz, Peter B. Galvin, and Greg Gagne, "Operating System Concepts", 9th Edition, Wiley. 1 Outline Background The Critical-Section

### 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

### 2.c Concurrency Mutual exclusion & synchronization mutexes. Unbounded buffer, 1 producer, N consumers

Mutual exclusion & synchronization mutexes Unbounded buffer, 1 producer, N consumers out shared by all consumers mutex among consumers producer not concerned: can still add items to buffer at any time

### Process Synchronization

Process Synchronization Reading: Silberschatz chapter 6 Additional Reading: Stallings chapter 5 EEL 358 1 Outline Concurrency Competing and Cooperating Processes The Critical-Section Problem Fundamental

### Concurrent Programming Issues & Readers/Writers

Concurrent Programming Issues & Readers/Writers 1 Summary of Our Discussions! Developing and debugging concurrent programs is hard Ø Non-deterministic interleaving of instructions! Safety: isolation and

### Using Semaphores CS 241. March 14, University of Illinois

Using Semaphores CS 241 March 14, 2012 University of Illinois Slides adapted in part from material accompanying Bryant & O Hallaron, Computer Systems: A Programmer's Perspective, 2/E 1 Announcements MP6

### Synchronization. CSCI 5103 Operating Systems. Semaphore Usage. Bounded-Buffer Problem With Semaphores. Monitors Other Approaches

Synchronization CSCI 5103 Operating Systems Monitors Other Approaches Instructor: Abhishek Chandra 2 3 Semaphore Usage wait(s) Critical section signal(s) Each process must call wait and signal in correct

### 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

### Semaphores INF4140. Lecture 3. 0 Book: Andrews - ch.04 ( ) INF4140 ( ) Semaphores Lecture 3 1 / 34

Semaphores INF4140 13.09.12 Lecture 3 0 Book: Andrews - ch.04 (4.1-4.4) INF4140 (13.09.12 ) Semaphores Lecture 3 1 / 34 Overview Last lecture: Locks and Barriers (complex techniques) No clear difference

### Operating Systems ECE344

Operating Systems ECE344 Ding Yuan Announcement & Reminder Lab 0 mark posted on Piazza Great job! One problem: compilation error I fixed some for you this time, but won t do it next time Make sure you

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

Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Objectives To present the concept of process synchronization. To introduce the critical-section problem, whose solutions can be used

### Condition Variables CS 241. Prof. Brighten Godfrey. March 16, University of Illinois

Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois 1 Synchronization primitives Mutex locks Used for exclusive access to a shared resource (critical section) Operations:

### Concurrency: Mutual Exclusion and

Concurrency: Mutual Exclusion and Synchronization 1 Needs of Processes Allocation of processor time Allocation and sharing resources Communication among processes Synchronization of multiple processes

### High Performance Computing Lecture 21. Matthew Jacob Indian Institute of Science

High Performance Computing Lecture 21 Matthew Jacob Indian Institute of Science Semaphore Examples Semaphores can do more than mutex locks Example: Consider our concurrent program where process P1 reads

### Module 5: Process Synchronization. Reading: Chapter 6

Module 5: Process Synchronization Reading: Chapter 6 1 Solutions Classic problems What is the problem? Process Synchronization Synchr. In Real Systems 2 Background Producer/Consumer Critical Section Problem

### 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:

### Parallelism and Concurrency. Motivation, Challenges, Impact on Software Development CSE 110 Winter 2016

Parallelism and Concurrency Motivation, Challenges, Impact on Software Development CSE 110 Winter 2016 About These Slides Due to the nature of this material, this lecture was delivered via the chalkboard.

### Synchronization II. q Condition Variables q Semaphores and monitors q Some classical problems q Next time: Deadlocks

Synchronization II q Condition Variables q Semaphores and monitors q Some classical problems q Next time: Deadlocks Condition variables Locks are not enough to build concurrent programs Many times a thread

### Opera&ng Systems ECE344

Opera&ng Systems ECE344 Lecture 6: Synchroniza&on (II) Semaphores and Monitors Ding Yuan Higher- Level Synchroniza&on We looked at using locks to provide mutual exclusion Locks work, but they have some

### 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?

### 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,

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

Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han Announcements HW #3 is coming, due Friday Feb. 25, a week+ from now PA #2 is coming, assigned about next Tuesday Midterm is tentatively

### Chapter 6 Concurrency: Deadlock and Starvation

Operating Systems: Internals and Design Principles Chapter 6 Concurrency: Deadlock and Starvation Seventh Edition By William Stallings Operating Systems: Internals and Design Principles When two trains

### Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - XI Deadlocks - II. Louisiana State University

CSC 4103 - Operating Systems Fall 2009 Lecture - XI Deadlocks - II Tevfik Ko!ar Louisiana State University September 29 th, 2009 1 Roadmap Classic Problems of Synchronization Bounded Buffer Readers-Writers

### 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

### 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

### Introduction to Embedded Systems. Lab Logistics

Introduction to Embedded Systems CS/ECE 6780/5780 Al Davis Today s topics: lab logistics interrupt synchronization reentrant code 1 CS 5780 Lab Logistics Lab2 Status Wed: 3/11 teams have completed their

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

Techno India Batanagar Department of Computer Science & Engineering Model Questions Subject Name: Operating System Multiple Choice Questions: Subject Code: CS603 1) Shell is the exclusive feature of a)

### Example of use. Shared var mutex: semaphore = 1; Process i. begin.. P(mutex); execute CS; V(mutex);.. End;

Example of use Shared var mutex: semaphore = 1; Process i P(mutex); execute CS; V(mutex); End; Other synchronization problems Semaphore can be used in other synchronization problems besides Mutual Exclusion

### CS450 OPERATING SYSTEMS FINAL EXAM ANSWER KEY

CS450 OPERATING SYSTEMS FINAL EXAM KEY 1. Provide Java class definitions for each of the components of a monitor. Include specifications for local data and methods (names and arguments, not implementation);

### Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

Brief Preview of Scheduling Concurrency Control Nan Niu (nn@cs.toronto.edu) CSC309 -- Summer 2008 Multiple threads ready to run Some mechanism for switching between them Context switches Some policy for

### Reminder from last time

Concurrent systems Lecture 2: More mutual exclusion, semaphores, and producer-consumer relationships DrRobert N. M. Watson 1 Reminder from last time Definition of a concurrent system Origins of concurrency

### 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

### Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst What is a Monitor? Ties data and the synchronization operations together Monitors guarantee mutual exclusion, i.e.,

### Computation structures. Support for problem-solving lesson #7

Computation structures Support for problem-solving lesson #7 Exercise 1 Give an implementation of the mutual exclusion between 2 processes using only the blocking message queues of size 0 as synchronization

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

Thread Disclaimer: some slides are adopted from the book authors slides with permission 1 IPC Shared memory Recap share a memory region between processes read or write to the shared memory region fast

### Semaphores and Monitors: High-level Synchronization Constructs

1 Synchronization Constructs Synchronization Coordinating execution of multiple threads that share data structures Semaphores and Monitors High-level Synchronization Constructs A Historical Perspective

### Reminder from last <me

Concurrent systems Lecture 2: Mutual exclusion and process synchronisa

### COMP SCI 3SH3: Operating System Concepts (Term 2 Winter 2006) Test 2 February 27, 2006; Time: 50 Minutes ;. Questions Instructor: Dr.

COMP SCI 3SH3: Operating System Concepts (Term 2 Winter 2006) Test 2 February 27, 2006; Time: 50 Minutes ;. Questions Instructor: Dr. Kamran Sartipi Name: Student ID: Question 1 (Disk Block Allocation):

### 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

### 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

### CS 333 Introduction to Operating Systems. Class 6 Monitors and Message Passing. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems Class 6 Monitors and Message Passing Jonathan Walpole Computer Science Portland State University 1 But first Continuation of Class 5 Classical Synchronization Problems

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

### Semaphores. Blocking in semaphores. Two types of semaphores. Example: Bounded buffer problem. Binary semaphore usage

Semaphores CSE 451: Operating Systems Spring 2013 Module 8 Semaphores, Condition Variables, and Monitors Ed Lazowska lazowska@cs.washington.edu Allen Center 570 Semaphore = a synchronization primitive

### WEEK 5 - APPLICATION OF PETRI NETS. 4.4 Producers-consumers problem with priority

4.4 Producers-consumers problem with priority The net shown in Fig. 27 represents a producers-consumers system with priority, i.e., consumer A has priority over consumer B in the sense that A can consume

### Synchronization Without Busy Waiting

Synchronization Without Busy Waiting The solutions we ve considered up to now, Dekker s and Peterson s algorithms and hardware testand-set all share an unpleasent attribute. processes waiting to enter

### Monitors (Deprecated)

D Monitors (Deprecated) Around the time concurrent programming was becoming a big deal, objectoriented programming was also gaining ground. Not surprisingly, people started to think about ways to merge

### There are 8 total numbered pages, 6 Questions. You have 60 minutes. Budget your time carefully!

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING MIDTERM EXAMINATION, March, 2017 Third Year Materials ECE344H1 - Operating Systems Calculator Type: 2 Exam Type: A Examiner D. Yuan Please

### EECS 482 Introduction to Operating Systems

EECS 482 Introduction to Operating Systems Fall 2017 Manos Kapritsos Slides by: Harsha V. Madhyastha Implementing reader-writer locks with monitors Shared data needed to implement readerstart, readerfinish,

### CS 25200: Systems Programming. Lecture 26: Classic Synchronization Problems

CS 25200: Systems Programming Lecture 26: Classic Synchronization Problems Dr. Jef Turkstra 2018 Dr. Jeffrey A. Turkstra 1 Announcements Lab 5 posted this evening Web server Password protection SSL cgi-bin

### Chapter 6: Process Synchronization

Module 6: Process Synchronization Chapter 6: Process Synchronization Background! The Critical-Section Problem! Peterson s Solution! Synchronization Hardware! Semaphores! Classic Problems of Synchronization!

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

CS341: Operating System Lect20 : 16 th Sept 2014 Dr. A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati Synchronization API of Pthread Mutex: lock, unlock, try_lock CondVar: wait,

### Lecture 3: Intro to Concurrent Processing using Semaphores

Lecture 3: Intro to Concurrent Processing using Semaphores Semaphores; The Prucer-Consumer problem; The Dining Philosophers problem; The Readers-Writers Problem: Readers Preference Passing the Baton Ballhausen