Operating Systems Mehdi Naghavi Winter 1385.

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

Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Parallel Programming – Barriers, Locks, and Continued Discussion of Parallel Decomposition David Monismith Jan. 27, 2015 Based upon notes from the LLNL.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 14: Deadlock & Dinning Philosophers.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Operating Systems Operating Systems - Winter 2009 Chapter 2 - Processes Vrije Universiteit Amsterdam.
02/27/2004CSCI 315 Operating Systems Design1 Process Synchronization Deadlock Notice: The slides for this lecture have been largely based on those accompanying.
Monitors A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process may be active within.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Classic Synchronization Problems.
Classic Synchronization Problems
Classical Problems of Concurrency
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Concurrency: Deadlock and Starvation Chapter 6. Revision Describe three necessary conditions for deadlock Which condition is the result of the three necessary.
1 CS 333 Introduction to Operating Systems Class 5 – Classical IPC Problems Jonathan Walpole Computer Science Portland State University.
Monitors CSCI 444/544 Operating Systems Fall 2008.
IPC and Classical Synchronization Problems
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Classical IPC and Synchronization Problems CS 342 – Operating Systems Ibrahim.
Definitions Process – An executing program
More Synchronisation Last time: bounded buffer, readers-writers, dining philosophers Today: sleeping barber, monitors.
1 Concurrency: Deadlock and Starvation Chapter 6.
© 2004, D. J. Foreman 1 High Level Synchronization and Inter-Process Communication.
1 Processes Chapter Processes 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Synchronization II: CPE Operating Systems
Thread Synchronization Tutorial #8 CPSC 261. A thread is a virtual processor Each thread is provided the illusion that it owns a core – Copy of the registers.
Chapter 2 Chapter 2: Processes & Threads Part 2 Interprocess Communication (IPC) & Synchronization.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Dining Philosophers A “Classical” Synchronization Problem devised by Edsger Dijkstra in 1965 (modified for the masses by Tony Hoare) You have –5 philosophers.
Operating Systems Inter-Process Communications. Lunch time in the Philosophy Department. Dining Philosophers Problem (1)
Distributed Systems 2 Distributed Processing. Process A process is a logical representation of a physical processor that executes program code and has.
Synchronisation Examples
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 13: Dinning Philosophers, and Misc.
CS 241 Section Week #7 (10/22/09). Topics This Section  Midterm Statistics  MP5 Forward  Classical Synchronization Problems  Problems.
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Dining Philosophers & Monitors Questions answered in this lecture: How to synchronize dining philosophers? What are monitors and condition variables? What.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
Deadlock and Starvation
Interprocess Communication Race Conditions
Classical IPC Problems
Dining Philosophers Five philosophers sit around a table
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Chapter 5: Process Synchronization – Part 3
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Process Synchronization
Chapter 5: Process Synchronization
Classical Synchronization Problems
Deadlock and Starvation
2.4 Classic IPC Problems Dining philosophers Readers and writers
Chapter 6: Process Synchronization
CSCI 511 Operating Systems Chapter 5 (Part C) Monitor
Chapter 5: Process Synchronization (Con’t)
Lecture 15: Dining Philosophers Problem
Lecture 25 Syed Mansoor Sarwar
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Module 7a: Classic Synchronization
Chapter 7: Synchronization Examples
Lecture 15: Dining Philosophers Problem
Chapter 7: Synchronization Examples
Presentation transcript:

Operating Systems Mehdi Naghavi Winter 1385

2 Class outline Introduction and Overview Processes Operating system structures Memory management Scheduling Input/Output File Systems Security

Operating Systems Mehdi Naghavi Winter 1385 Processes

4 Overview: Processes Threads Scheduling Interprocess communication Classical IPC problems

Processes Mehdi Naghavi Winter 1385

Classical IPC problems Mehdi Naghavi Spring 1386 Classical synchronization problems

7 Dining Philosophers N philosophers around a table All are hungry All like to think N chopsticks available 1 between each pair of philosophers Philosophers need two chopsticks to eat Philosophers alternate between eating and thinking Goal: coordinate use of chopsticks

8 A nonsolution to the dining philosophers problem

9 Code for philosopher i while(1) { chopstick[i].down(); chopstick[(i+1)%n].down(); // eat chopstick[i].up(); chopstick[(i+1)%n].up(); // think } Shared variables const int n; // initialize to 1 Semaphore chopstick[n]; Dining Philosophers: solution 1 Use a semaphore for each chopstick A hungry philosopher Gets the chopstick to his right Gets the chopstick to his left Eats Puts down the chopsticks Potential problems? Deadlock Fairness

10 Code for philosopher i int i1,i2; while(1) { if (i != (n-1)) { i1 = i; i2 = i+1; } else { i1 = 0; i2 = n-1; } chopstick[i1].down(); chopstick[i2].down(); // eat chopstick[i1].up(); chopstick[i2].up(); // think } Shared variables const int n; // initialize to 1 Semaphore chopstick[n]; Dining Philosophers: solution 2 Use a semaphore for each chopstick A hungry philosopher Gets lower, then higher numbered chopstick Eats Puts down the chopsticks Potential problems? Deadlock Fairness

11 Dining Philosophers (3) Solution to dining philosophers problem (part 1)

12 Dining Philosophers (4) Solution to dining philosophers problem (part 2)

13 Dining philosophers with locks Shared variables const int n; // initialize to THINK int state[n]; Lock mutex; // use mutex for self Condition self[n]; Code for philosopher j while (1) { // pickup chopstick mutex.Acquire(); state[j] = HUNGRY; test(j); if (state[j] != EAT) self[j].Wait(); mutex.Release(); // eat mutex.Acquire(); state[j] = THINK; test((j+1)%n); // next test((j+n-1)%n); // prev mutex.Release(); // think } void test(int k) { if ((state[(k+n-1)%n)]!=EAT) && (state[k]==HUNGRY) && (state[(k+1)%n]!=EAT)) { state[k] = EAT; self[k].Signal(); }

14 A solution to the Readers and Writers Problem

15 The Sleeping Barber Problem

16 Solution to sleeping barber problem.