1 Processes and Threads Part II Chapter 2 2.1 Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Operating Systems Mehdi Naghavi Winter 1385.
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 2 Processes and Threads
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Mutual Exclusion.
Interprocess Communication
Operating Systems Operating Systems - Winter 2009 Chapter 2 - Processes Vrije Universiteit Amsterdam.
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
EEE 435 Principles of Operating Systems Interprocess Communication Pt I (Modern Operating Systems 2.3)
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
Concurrency, Race Conditions, Mutual Exclusion, Semaphores, Monitors, Deadlocks Chapters 2 and 6 Tanenbaum’s Modern OS.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Interprocess Communication
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
Chapter 2.3 : Interprocess Communication
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Outline Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Processes (Διεργασίες)
1 Processes Chapter Processes 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Process Synchronization Tanenbaum Ch 2.3, 2.5 Silberschatz Ch 6.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Operating Systems Inter-Process Communications. Lunch time in the Philosophy Department. Dining Philosophers Problem (1)
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
1 Interprocess Communication Yücel Saygın | These slides are based on your text book and on the slides prepared by Andrew S. Tanenbaum.
Operating Systems COMP 4850/CISG 5550 Interprocess Communication, Part II Dr. James Money.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Inter Process Communication
Interprocess Communication Race Conditions
Classical IPC Problems
Lecture 11: Mutual Exclusion
Lecture 16: Readers-Writers Problem and Message Passing
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Concurrency: Mutual Exclusion and Synchronization
Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
Lecture 16: Readers-Writers Problem and Message Passing
Lecture 11: Mutual Exclusion
Interprocess Communication & Synchronization
CSE 542: Operating Systems
CSE 542: Operating Systems
Synchronization CSE 2431: Introduction to Operating Systems
Presentation transcript:

1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling

2 2.3 Interprocess Communication Race Conditions Two processes want to access shared memory (variable in) at same time and they may put their files in the same slot Race Condition: When more than one process shares the same memory and the final result depends on the order of execution

Critical Regions (1) 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

Critical Regions (2) Mutual exclusion using critical regions

Mutual Exclusion with Busy Waiting (1) Disabling interrupts –Each process disables all interrupts just after entering its critical region(CR) and enables all interrupts before leaving it –Unsafe for user processes able to turn off all interrupts Lock Variables –Having a shared variable (lock), initially 0 –Before entering its CR the process checks lock, if lock is1, it waits; if lock is 0, it sets lock to 1 and enters its CR. –Before leaving its CR, the process resets lock to 0 –It does not work, why?

Mutual Exclusion with Busy Waiting (2) Proposed solution to critical region problem (a) Process 0. (b) Process 1. Variable turn is shared by both processes Strict Alternation

Mutual Exclusion with Busy Waiting(3) Peterson's solution

8 Mutual Exclusion with Busy Waiting (4) TSL(Test and Set Lock) Machine instruction Format: TSL RX, LOCK// LOCK is a shared variable, RX: a register Function: RX  LOCK LOCK  1 Since it is a machine instruction, so it is always executed atomically.

Semaphores (1) Definition: Class Semaphore { Private: value: integer; list: list of processes Public: void down() { value = value –1; if value < 0 { list.insert(this process) sleep(); } void up() { value = value + 1; if value <= 0 { p = list.remove(); wakeup(p); }

10 Semaphore (2) Semaphores are system facilities The up() and down() operations are system calls. The operating system guarantees that the two operations are atomic operations. I.e., when an up() or down() is being executed, no other up() and down() would be executed on the same semaphore.

11 Semaphore: application Control execution sequence –E.g., three processes: p1, p2 and p3, and p3’s stmnt3 must be executed after p1’stmnt1 and p2’s stmnt2 have completed. Semaphore seq = 0; P1p2p3 ……… Stmnt1;stmnt2Seq.down(); Seq.up();Seq.up(); Seq.down(); ……stmnt3 Mutual exclusion Semaphore mutex = 1; P1p2 Mutex.down();mutex.down(); Critical region;critical region Mutex.up();mutex.up()

Semaphores: application The producer-consumer problem using semaphores

Implementations of Semaphore (3) Disable all interrupts Use Peterson’s algorithm and treat the up() and down() operations as critical regions.

Mutexes Implementation of mutex_lock and mutex_unlock

Message Passing (1) Processes can communicate with each other via message passing. The operating system provides two primitive functions: –Send(dest, &message); –Receive(source, &message); Design issues: –Sender waits for acknowledgement, no buffer needed –When sender does not wait, the OS must maintain a buffer –Message scramble and loss

Message Passing (2) The producer-consumer problem with N messages

Classical IPC Problems The producer and consumer problem

Dining Philosophers (1) Philosophers eat/think Eating needs 2 forks Pick one fork at a time

Dining Philosophers (2) A nonsolution to the dining philosophers problem Deadlock? How?How to prevent deadlock

The Readers and Writers Problem (1) Multiple readers and writers need to access the database Readers only read the content Writers modify the database Multiple readers may read at the same time Only one writer is allowed to write at a time When a writer is writing, no reader is allowed to read

The Readers and Writers Problem (2)