Process Synchronization
|
|
- Lucas Amos Riley
- 5 years ago
- Views:
Transcription
1 Process Synchronization Part II, Modified by M.Rebaudengo Silberschatz, Galvin and Gagne 2009
2 Classical Problems of Synchronization Consumer/Producer with Bounded-Buffer Problem s and s Problem Dining-Philosophers Problem The three problems are important, because they are examples for a large class of concurrency-control problems. used for testing nearly every newly proposed synchronization scheme. Semaphores are used for synchronization in our solutions. 6.2 Silberschatz, Galvin and Gagne 2009
3 Consumer/Producer with Bounded Buffer Two processes (at least) use a shared buffer in memory The buffer is finite (i.e. bounded) The producer writes on the buffer and the consumer reads from it A full buffer stops the producer An empty buffer stops the consumer buffer of size n producer consumer 6.3 Silberschatz, Galvin and Gagne 2009
4 Bounded buffer (II) Producer Producer Consumer Consumer Consumer 6.4 Silberschatz, Galvin and Gagne 2009
5 Bounded-Buffer Problem (cont.) Correctness Constraints: Consumer must wait for producer to fill buffers, if empty (scheduling constraint) Producer must wait for consumer to empty buffers, if full (scheduling constraint) Only one thread can manipulate buffer queue at a time (mutual exclusion) 3 Semaphores: mutex full empty. 6.5 Silberschatz, Galvin and Gagne 2009
6 Bounded-Buffer Problem Shared data: semaphore full, empty, mutex; Initially: full = 0 empty = n mutex = 1 # of full cells # of empty cells 6.6 Silberschatz, Galvin and Gagne 2009
7 Bounded-Buffer Problem append(v) { b[in] = v; in = (in+1) % N; take() { w = b[out]; out =(out+1) % N; return w; append(v): a function, used by the producer, to add an item v to the buffer in the next position (b[in]).. take():a function, used by the consumer, to remove the next item from the buffer (b[out]) to prepare for consuming. append and take are critical sections because they use the shared buffer. 6.7 Silberschatz, Galvin and Gagne 2009
8 Bounded Buffer Problem (Cont.) Producer do { produce item 0, iff no wait(empty); cells wait(mutex); append (item) ; signal(mutex); signal(full); while (1); add one item Consumer do { wait(full); wait(mutex); item = take(); signal(mutex); signal(empty); consume the item while (1); 0, iff no item free one cell 6.8 Silberschatz, Galvin and Gagne 2009
9 Bad solution Producer do { produce item wait(empty); wait(mutex); append (item) ; signal(mutex); signal(full); while (1); Consumer do { wait(mutex); wait(full); item = take(); signal(mutex); signal(empty); consume the item while (1); 6.9 Silberschatz, Galvin and Gagne 2009
10 Order matters The order of the two P( ) operations is very important Neither the producer or the consumer should request exclusive access to the buffer before being sure they can perform the operation they have to perform The order of the two V( ) operations does not matter 6.10 Silberschatz, Galvin and Gagne 2009
11 s-s Problem s s 6.11 Silberschatz, Galvin and Gagne 2009
12 s-s Problem Shared Resource It s logically acceptable for an arbitrary number of readers to access the shared resource at the same time but if a writer is accessing the shared resource, it s unsafe to allow any other reader or writer to access it at the same time Silberschatz, Galvin and Gagne 2009
13 s-s Problem OK Shared Resource OK Shared Resource Operating Computer Science System Dept Concepts Va Tech September 8 th Edition Silberschatz, Galvin 2006 McQuain and Gagne & Ribbens 2009
14 s-s Problem Not OK Shared Resource 6.14 Silberschatz, Galvin and Gagne 2009
15 s-s Problem A data set is shared among a number of concurrent processes s only read the data set; they do not perform any updates. Many readers may access a database without fear of data corruption (interference) s can both read and write Problem allow multiple readers to read at the same time. Only one single writer can access the shared data at the same time s Shared object, e.g. file s a writer must have exclusive access W1 W2 R1 R2 s can share with any other reader but not a writer 6.15 Silberschatz, Galvin and Gagne 2009
16 s-s Problem There can be only one writer at a time, but there can be many simultaneous readers. Each writer has exclusive access. Options: 1. readers wait only if a writer has already obtained access permission (no reader will be kept waiting if there are writers waiting) 2. s have priority, start right away, temporarily blocking readers. Once a writer is ready, that writer has to perform its write as soon as possible, after old readers (or writer) are completed. Thus, if a writer is waiting to access the object, no new readers may start reading. A solution to either problem may result in starvation. with reader precedence: s with writer precedence: s Silberschatz, Galvin and Gagne 2009
17 s-s Problem Shared Data: Data set Integer readcount initialized to 0 (current number of readers) Semaphore mutex initialized to 1 (protect readcount updates) Semaphore wrt initialized to 1 (protect exclusion of writers) 6.17 Silberschatz, Galvin and Gagne 2009
18 A solution for the first problem The mutex (init =1) semaphore is used to ensure mutual exclusion when the variable readcount is updated. Readcount (init =0) keeps track of how many processes are currently reading the object. The wrt (init =1) semaphore functions as a mutual exclusion semaphore for the writers. It also is used by the first or last reader that enters or exits the critical section. It is not used by the readers who enter or exit while other processes are in their critical sections Silberschatz, Galvin and Gagne 2009
19 s-s Problem #1 Process while(true) { wait(wrt); writing is performed signal(wrt); 6.19 Silberschatz, Galvin and Gagne 2009
20 s-s Problem #1 Process mutex protects readcount updates mutex protects readcount updates while(true) { wait(mutex); readcount++; if (readcount == 1) First in wait(wrt); signal(mutex); reading is performed wait(mutex); readcount--; if (readcount == 0) signal(wrt); signal(mutex); The last reader sends a signal and, a reader or a writer, may be scheduled 6.20 Silberschatz, Galvin and Gagne 2009
21 The s/s Problem #1 If multiple writers seek to write, then the write semaphore wrt provides mutual exclusion If the 1st reader tries to read while a writer is writing, then the 1st reader blocks on wrt if subsequent readers try to read while a writer is writing, they block on wrt If the 1st reader reads and there are no writers, then 1st reader grabs the write lock and continues reading, eventually releasing the write lock when done reading if a writer tries to write while the 1st reader is reading, then the writer blocks on the write lock wrt if a 2nd or any subsequent reader tries to read while the 1st reader is reading, then it falls through and is allowed to read. s can starve writers Updates can be delayed forever May not be what we want Silberschatz, Galvin and Gagne 2009
22 s-s Problem #1: comments If a writer is in the CS and n readers are waiting, then one is queued on wrt the other n-1 are queued on mutex When a writer executes signal(wrt), either the waiting readers or a single writer are resumed. The selection is made by the scheduler Silberschatz, Galvin and Gagne 2009
23 s-s Problem #2: writer precedence reader() { while(true) { <other computing>; P(readBlock); P(mutex1); readcount++; if(readcount == 1) P(writeBlock); V(mutex1); V(readBlock); access(resource); P(mutex1); readcount--; if(readcount == 0) V(writeBlock); V(mutex1); int readcount = 0, writecount = 0; semaphore mutex1 = 1, mutex2 = 1; semaphore readblock = 1, writeblock = 1; writer() { while(true) { <other computing>; P(mutex2); writecount++; if(writecount == 1) P(readBlock); V(mutex2); P(writeBlock); access(resource); V(writeBlock); P(mutex2) writecount--; if(writecount == 0) V(readBlock); V(mutex2); 6.23 Silberschatz, Galvin and Gagne 2009
24 s-s Problem #2: writer precedence reader() { while(true) { <other computing>; 1 2 P(readBlock); P(mutex1); readcount++; if(readcount == 1) P(writeBlock); V(mutex1); V(readBlock); access(resource); P(mutex1); readcount--; if(readcount == 0) V(writeBlock); V(mutex1); int readcount = 0, writecount = 0; semaphore mutex1 = 1, mutex2 = 1; semaphore readblock = 1, writeblock = 1; writer() { while(true) { <other computing>; P(mutex2); writecount++; if(writecount == 1) 3 P(readBlock); V(mutex2); P(writeBlock); access(resource); V(writeBlock); P(mutex2) writecount--; if(writecount == 0) V(readBlock); V(mutex2); First does a P(readBlock) to block any new readers 6.24 Silberschatz, Galvin and Gagne 2009
25 s-s Problem #2: writer precedence reader() { while(true) { <other computing>; P(readBlock); P(mutex1); readcount++; if(readcount == 1) P(writeBlock); V(mutex1); did a P(readBlock) V(readBlock); Next reader is blocked because the first writer access(resource); P(mutex1); readcount--; if(readcount == 0) V(writeBlock); V(mutex1); int readcount = 0, writecount = 0; semaphore mutex1 = 1, mutex2 = 1; semaphore readblock = 1, writeblock = 1; writer() { while(true) { <other computing>; P(mutex2); writecount++; if(writecount == 1) P(readBlock); V(mutex2); 3 P(writeBlock); access(resource); V(writeBlock); P(mutex2) writecount--; if(writecount == 0) V(readBlock); V(mutex2); blocks on P(writeBlock) 6.25 Silberschatz, Galvin and Gagne 2009
26 s-s Problem #2: writer precedence reader() { while(true) { <other computing>; 4 2 P(readBlock); P(mutex1); readcount++; if(readcount == 1) P(writeBlock); V(mutex1); V(readBlock); access(resource); P(mutex1); readcount--; if(readcount == 0) V(writeBlock); V(mutex1); Last reader signals 1 int readcount = 0, writer writecount to begin = 0; semaphore mutex1 = 1, mutex2 = 1; semaphore readblock = 1, writeblock = 1; writer() { while(true) { <other computing>; P(mutex2); writecount++; if(writecount == 1) P(readBlock); V(mutex2); 3 P(writeBlock); access(resource); V(writeBlock); P(mutex2) writecount--; if(writecount == 0) V(readBlock); V(mutex2); 6.26 Silberschatz, Galvin and Gagne 2009
27 s-s Problem #2: writer precedence reader() { while(true) { <other computing>; 4 P(readBlock); P(mutex1); readcount++; Any new if(readcount reader must == 1) P(writeBlock); wait until the last writer V(mutex1); V(readBlock); signals access(resource); P(mutex1); readcount--; if(readcount == 0) V(writeBlock); V(mutex1); int readcount = 0, writecount = 0; semaphore mutex1 = 1, mutex2 = 1; semaphore readblock = 1, writeblock = 1; writer() { while(true) { <other computing>; P(mutex2); writecount++; if(writecount == 1) P(readBlock); V(mutex2); 5 P(writeBlock); 3 access(resource); V(writeBlock); P(mutex2) writecount--; if(writecount == 0) Any new writer has priority over any waiting reader but is stuck until first writer is finished V(readBlock); V(mutex2); 6.27 Silberschatz, Galvin and Gagne 2009
28 s-s Problem #2: comments Any writer must wait for current readers to finish Any writer has priority over any new readers The writers can starve readers Reads can be delayed forever May not be what we want Silberschatz, Galvin and Gagne 2009
29 Dining Philosophers Problem Model allocating several resources among several processes. The Dining Philosophers Problem stated (1965) as follows. Five philosophers are seated around a circular table Five plates of foods (spaghetti in the original Dijkstra's paper ) Five chopstics (forks) Between each pair of plates there is one fork Philosophers spend time eating and thinking: Philosophers think about the world and ignore food When they want to eat, need two forks Pick up one and then the other one Silberschatz, Galvin and Gagne 2009
30 Each philosopher is modeled with a thread while(true) { Think(); Grab first fork; Grab second fork; Eat(); Put down first fork; Put down second fork; 6.30 Silberschatz, Galvin and Gagne 2009
31 Philosopher Process Shared data spaghetti (data set) Semaphore fork [5] initialized to 1 Philosopher i: repeat wait( fork[ i]); // get left fork wait( fork[ i+1 mod 5]); // right fork eat signal( fork[ i]); // return left fork signal( fork[ i+1 mod 5]); // return right fork think until false; 6.31 Silberschatz, Galvin and Gagne 2009
32 Simplest Example of Deadlock In this algorithm, take-fork waits until the specified fork is available. The solution is wrong because If all five philosophers take their left fork simultaneously there will be deadlock (i.e., processes stay blocked forever). Thread 0 Interleaving Thread 1 P(R1) P(R2) V(R1) V(R2) P(R1) P(R2) P(R1) waits P(R2) waits P(R2) P(R1) V(R2) V(R1) 6.32 Silberschatz, Galvin and Gagne 2009
33 Remedies Teach philosophers to eat spaghetti with 1 fork! Give them another fork Allow at most 4 philosophers at the table Use asymmetry odd philosophers pick up left first, while even philosophers pick up right first Check to see if both forks are available, then pick them up Besides deadlock, any satisfactory solution to the DP problem must avoid the problem of starvation Silberschatz, Galvin and Gagne 2009
34 Admit only 4 philosophers Then 1 philosopher can always eat when the other 3 are holding 1 fork Hence, we can use another semaphore T that would limit at 4 the number of philosophers sitting at the table Process Pi: repeat think; wait(t); wait(fork[i]); wait(fork[i+1 mod 5]); eat; signal(fork[i+1 mod 5]); signal(fork[i]); signal(t); forever 6.34 Silberschatz, Galvin and Gagne 2009
35 Working towards a solution #define N 5 Philosopher() { while(true) { Think(); take_fork(i); take_fork((i+1)% N); Eat(); put_fork(i); put_fork((i+1)% N); take_forks(i) put_forks(i) 6.35 Silberschatz, Galvin and Gagne 2009
36 Working towards a solution #define N 5 Philosopher() { while(true) { Think(); take_forks(i); Eat(); put_forks(i); 6.36 Silberschatz, Galvin and Gagne 2009
37 Picking up forks initial values int state[n] semaphore mutex = 1 semaphore sem[i] take_forks(int i) { wait(mutex); state [i] = HUNGRY; test(i); signal(mutex); wait(sem[i]); // only called with mutex set! test(int i) { if (state[i] == HUNGRY && state[left]!= EATING && state[right]!= EATING){ state[i] = EATING; signal(sem[i]); 6.37 Silberschatz, Galvin and Gagne 2009
38 Putting down forks int state[n] semaphore mutex = 1 semaphore sem[i] put_forks(int i) { wait(mutex); state [i] = THINKING; test(left); test(right); signal(mutex); // only called with mutex set! test(int i) { if (state[i] == HUNGRY && state[left]!= EATING && state[right]!= EATING){ state[i] = EATING; signal(sem[i]); 6.38 Silberschatz, Galvin and Gagne 2009
Classic Problems of Synchronization
Classic Problems of Synchronization Bounded-Buffer Problem s-s Problem Dining Philosophers Problem Monitors 2/21/12 CSE325 - Synchronization 1 s-s Problem s s 2/21/12 CSE325 - Synchronization 2 Problem
More informationSynchronization Classic Problems
CS 4410 Operating Systems Synchronization Classic Problems Summer 2013 Cornell University 1 Today What practical problems can we solve with semaphores? Bounded-Buffer Problem Producer-Consumer Problem
More informationLecture 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
More information5 Classical IPC Problems
OPERATING SYSTEMS CLASSICAL IPC PROBLEMS 2 5 Classical IPC Problems The operating systems literature is full of interesting problems that have been widely discussed and analyzed using a variety of synchronization
More informationCS370 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,
More informationSemaphores. To avoid busy waiting: when a process has to wait, it will be put in a blocked queue of processes waiting for the same event
Semaphores Synchronization tool (provided by the OS) that do not require busy waiting A semaphore S is an integer variable that, apart from initialization, can only be accessed through 2 atomic and mutually
More informationSemaphores. Semaphores. Semaphore s operations. Semaphores: observations
Semaphores Synchronization tool (provided by the OS) that do not require busy waiting A semaphore S is an integer variable that, apart from initialization, can only be accessed through 2 atomic and mutually
More informationChapter 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
More informationBasic Synchronization Principles
Basic Synchronization Principles Encourage Concurrency No widely-accepted concurrent programming languages No concurrent programming paradigm Each problem requires careful consideration There is no common
More informationCSE 4/521 Introduction to Operating Systems
CSE 4/521 Introduction to Operating Systems Lecture 7 Process Synchronization II (Classic Problems of Synchronization, Synchronization Examples) Summer 2018 Overview Objective: 1. To examine several classical
More informationChapter 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 informationChapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd 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 informationProcess 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
More informationChapter 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 informationProcess 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 informationChapter 7: Process Synchronization. Background
Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris
More informationEI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)
EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture) Dept. of Computer Science & Engineering Chentao Wu wuct@cs.sjtu.edu.cn Download lectures ftp://public.sjtu.edu.cn User:
More informationBackground. 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
More informationCS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University
Frequently asked questions from the previous class survey CS 370: SYSTEM ARCHITECTURE & SOFTWARE [PROCESS SYNCHRONIZATION] Shrideep Pallickara Computer Science Colorado State University Semaphores From
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 1018 L11 Synchronization Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel feedback queue:
More informationRoadmap. 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
More informationRoadmap. Bounded-Buffer Problem. Classical Problems of Synchronization. Bounded Buffer 1 Semaphore Soln. Bounded Buffer 1 Semaphore Soln. Tevfik Ko!
CSC 4103 - Operating Systems Fall 2009 Lecture - XI Deadlocks - II Roadmap Classic Problems of Synchronization Bounded Buffer Readers-Writers Dining Philosophers Sleeping Barber Deadlock Prevention Tevfik
More informationSemaphores (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
More informationProf. Hui Jiang Dept of Computer Science and Engineering York University
0./ ' )-, ' ' # # 2 H; 2 7 E 7 2 $&% ( Prof. Hui Jiang ept of omputer Science and Engineering York University )+* Problems with the software solutions. Not easy to generalize to more complex synchronization
More informationModule 6: Process Synchronization
Module 6: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris
More informationChapter 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 informationOutline for Today. Readers/Writers Problem
Objective: Outline for Today Reader-writer problem Message Passing Administrative details: Check that you know where your demo will be For me, Microsoft Lab on 2 nd floor LSRC. 1 Readers/Writers Problem
More informationChapter 5: Process Synchronization
Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Operating System Concepts 9th Edition Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution
More informationCS 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
More informationChapter 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 informationSynchronization. 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
More informationSemaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }
Semaphore Semaphore S integer variable Two standard operations modify S: wait() and signal() Originally called P() and V() Can only be accessed via two indivisible (atomic) operations wait (S) { while
More informationProcess Synchronization
CSC 4103 - Operating Systems Spring 2007 Lecture - VI Process Synchronization Tevfik Koşar Louisiana State University February 6 th, 2007 1 Roadmap Process Synchronization The Critical-Section Problem
More informationInterprocess 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 informationSynchronization. CS 475, Spring 2018 Concurrent & Distributed Systems
Synchronization CS 475, Spring 2018 Concurrent & Distributed Systems Review: Threads: Memory View code heap data files code heap data files stack stack stack stack m1 m1 a1 b1 m2 m2 a2 b2 m3 m3 a3 m4 m4
More informationProcess Synchronization. studykorner.org
Process Synchronization Semaphore Implementation Must guarantee that no two processes can execute wait () and signal () on the same semaphore at the same time The main disadvantage of the semaphore definition
More informationRoadmap. Readers-Writers Problem. Readers-Writers Problem. Readers-Writers Problem (Cont.) Dining Philosophers Problem.
CSE 421/521 - Operating Systems Fall 2011 Lecture - X Process Synchronization & Deadlocks Roadmap Classic Problems of Synchronization Readers and Writers Problem Dining-Philosophers Problem Sleeping Barber
More informationOperating 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 informationLesson 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 informationSynchronization 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
More informationCHAPTER 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
More informationProcess Synchronization(2)
EECS 3221.3 Operating System Fundamentals No.6 Process Synchronization(2) Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University Semaphores Problems with the software solutions.
More informationProcess Synchronization(2)
CSE 3221.3 Operating System Fundamentals No.6 Process Synchronization(2) Prof. Hui Jiang Dept of Computer Science and Engineering York University Semaphores Problems with the software solutions. Not easy
More information5 Dining Philosophers. Template for Philosopher. Naive Solution. while (food available) /*pick up forks*/ eat; /*put down forks*/ think awhile;
5 Dining Philosophers Philosopher 4 Philosopher 3 Philosopher 0 while(food available) pick up 2 adj. forks; put down forks; Philosopher 1 Philosopher 2 90 Template for Philosopher /*pick up forks*/ /*put
More informationProcess 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 informationCS3502 OPERATING SYSTEMS
CS3502 OPERATING SYSTEMS Spring 2018 Synchronization Chapter 6 Synchronization The coordination of the activities of the processes Processes interfere with each other Processes compete for resources Processes
More informationProcess Synchronization
Process Synchronization Daniel Mosse (Slides are from Silberschatz, Galvin and Gagne 2013 and Sherif Khattab) Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution
More informationPESIT Bangalore South Campus
INTERNAL ASSESSMENT TEST II Date: 04/04/2018 Max Marks: 40 Subject & Code: Operating Systems 15CS64 Semester: VI (A & B) Name of the faculty: Mrs.Sharmila Banu.A Time: 8.30 am 10.00 am Answer any FIVE
More informationOS 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
More informationOutline for Today. 5 Dining Philosophers. Template for Philosopher. Naive Solution. Objective: Administrative details:
Outline for Today Objective: 5 Dining Philosophers Reader-writer problem Message Passing Administrative details: Check for demo location with grader TA s and me: come to our offices UTA s if they don t
More informationChapter 8. Basic Synchronization Principles
Chapter 8 Basic Synchronization Principles Need for Synchronization Multiprogramming Multiple concurrent, independent processes Those processes might want to coordinate activities Proc A { while (true)
More informationTopic 4: Synchronization with Semaphores
CS 414 : Operating Systems UNIVERSITY OF VIRGINIA Department of Computer Science Fall 2005 Topic 4: Synchronization with Semaphores Readings for this topic: Sections 6.1-6.6 The too-much-milk solution
More informationChapter 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 informationChapter 5: Process Synchronization
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 informationConcept of a process
Concept of a process In the context of this course a process is a program whose execution is in progress States of a process: running, ready, blocked Submit Ready Running Completion Blocked Concurrent
More information9/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
More informationProcess Synchronization
CS307 Process Synchronization Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2018 Background Concurrent access to shared data may result in data inconsistency
More informationChapter 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
More informationProcess 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
More informationChapter 7: Process Synchronization!
Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Monitors 7.1 Background Concurrent access to shared
More informationProcess 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
More informationChapter 6: Process Synchronization
Chapter 6: Process Synchronization Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization
More informationProcesses. Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra
Processes Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra Processes Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication Process Concept Early
More informationProcess Synchronization(2)
EECS 3221.3 Operating System Fundamentals No.6 Process Synchronization(2) Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University Semaphores Problems with the software solutions.
More informationSections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour
Course CS350 - Operating Systems Sections 01 (11:30), 02 (16:00), 03 (8:30) Instructor Ashraf Aboulnaga & Borzoo Bonakdarpour Date of Exam October 25, 2011 Time Period 19:00-21:00 Duration of Exam Number
More informationCS 361 Concurrent programming Drexel University Spring 2000 Lecture 14. The dining philosophers problem
CS 361 Concurrent programming Drexel University Spring 2000 Lecture 14 Bruce Char. All rights reserved by the author. Permission is given to students enrolled in CS361 Spring 2000 to reproduce these notes
More informationHigh-level Synchronization
Recap of Last Class High-level Synchronization CS 256/456 Dept. of Computer Science, University of Rochester Concurrent access to shared data may result in data inconsistency race condition. The Critical-Section
More informationProcess 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
More informationSynchronization. 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 informationChapter 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
More informationIntroduction 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 informationBack to synchronization
Back to synchronization The dining philosophers problem Deadlocks o Modeling deadlocks o Dealing with deadlocks Operating Systems, 28, I. Dinur, D. Hendler and R. Iakobashvili The Dining Philosophers Problem
More informationSynchronization. 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
More informationCSE 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
More informationSemaphores. 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 informationOperating Systems CMPSC 473. Synchronization February 26, Lecture 12 Instructor: Trent Jaeger
Operating Systems CMPSC 473 Synchronization February 26, 2008 - Lecture 12 Instructor: Trent Jaeger Last class: Synchronization Problems and Primitives Today: Synchonization Solutions Midterm (Both Sections)
More informationChapter 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 informationYet another synchronization problem
Yet another synchronization problem The dining philosophers problem Deadlocks o Modeling deadlocks o Dealing with deadlocks Operating Systems, 25, Meni Adler, Danny Hendler & Roie Zivan The Dining Philosophers
More informationSilberschatz and Galvin Chapter 6
Silberschatz and Galvin Chapter 6 Process Synchronization CPSC 410--Richard Furuta 2/26/99 1 Topics discussed Process synchronization Mutual exclusion--hardware Higher-level abstractions Ð Semaphores Ð
More informationChapter 6: Process Synchronization. Module 6: Process Synchronization
Chapter 6: Process Synchronization Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization
More informationProcess 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
More informationSynchronization. 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 informationChapter 6: Process Synchronization. Operating System Concepts 8 th Edition,
Chapter 6: Process Synchronization, Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores
More informationReaders/Writers Problem. Readers/Writers: Scenario 1. Readers/Writers Problem. Today: Synchronization for Readers/Writers Problem
Today: Synchronization for Readers/Writers Problem An object is shared among may threads, each belonging to one of two classes: Readers: read data, never modify it Writers: read data and modify it Using
More informationProcess Synchronization: Semaphores. CSSE 332 Operating Systems Rose-Hulman Institute of Technology
Process Synchronization: Semaphores CSSE 332 Operating Systems Rose-Hulman Institute of Technology Critical-section problem solution 1. Mutual Exclusion - If process Pi is executing in its critical section,
More informationProcess Synchronization. CISC3595, Spring 2015 Dr. Zhang
Process Synchronization CISC3595, Spring 2015 Dr. Zhang 1 Concurrency OS supports multi-programming In single-processor system, processes are interleaved in time In multiple-process system, processes execution
More informationChapter 6: Process Synchronization. Operating System Concepts 9 th Edit9on
Chapter 6: Process Synchronization Operating System Concepts 9 th Edit9on Silberschatz, Galvin and Gagne 2013 Objectives To present the concept of process synchronization. To introduce the critical-section
More informationOperating Systems Antonio Vivace revision 4 Licensed under GPLv3
Operating Systems Antonio Vivace - 2016 revision 4 Licensed under GPLv3 Process Synchronization Background A cooperating process can share directly a logical address space (code, data) or share data through
More informationLecture 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
More informationOperating 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 informationDepartment of CSIT ( G G University, Bilaspur ) Model Answer 2013 (Even Semester) - AR-7307
Department of CSIT ( G G University, Bilaspur ) Model Answer 2013 (Even Semester) - AR-7307 Class: MCA Semester: II Year:2013 Paper Title: Principles of Operating Systems Max Marks: 60 Section A: (All
More informationReal-Time Operating Systems M. 5. Process Synchronization
Real-Time Operating Systems M 5. Process Synchronization Notice The course material includes slides downloaded from: http://codex.cs.yale.edu/avi/os-book/ and (slides by Silberschatz, Galvin, and Gagne,
More informationChapter 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!
More informationChapter 6: Synchronization
Chapter 6: Synchronization Module 6: Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization
More informationChapter 6: Process Synchronization. Operating System Concepts 8 th Edition,
Chapter 6: Process Synchronization, Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores
More informationRoadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - X Deadlocks - I. University at Buffalo. Synchronization structures
CSE 421/521 - Operating Systems Fall 2012 Lecture - X Deadlocks - I Tevfik Koşar University at Buffalo October 2nd, 2012 1 Roadmap Synchronization structures Problems with Semaphores Monitors Condition
More informationRoadmap. Problems with Semaphores. Semaphores. Monitors. Monitor - Example. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012
CSE 421/521 - Operating Systems Fall 2012 Lecture - X Deadlocks - I Tevfik Koşar Synchronization structures Problems with Semaphores Monitors Condition Variables Roadmap The Deadlock Problem Characterization
More informationConcurrency pros and cons. Concurrent Programming Problems. Mutual Exclusion. Concurrency is good for users
Concurrency pros and cons Con Programming Problems OS Spring 2009 Concurrency is good for users One of the reasons for multiprogramming Working on the same problem, simultaneous execution of programs,
More informationChapter 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 informationCS370 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