Lecture 20 Syed Mansoor Sarwar

Slides:



Advertisements
Similar presentations
Operating Systems Part III: Process Management (Process Synchronization)
Advertisements

Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Process Synchronization Continued 7.2 The Critical-Section Problem.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
China’s Software Industry August 2006 Instructor: Hengming Zou, Ph.D.
1 Course Syllabus 1. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation.
Silberschatz, Galvin and Gagne  Operating System Concepts Background Shared-memory solution to bounded-buffer problem allows at most n – 1 items.
CPSC 668Set 7: Mutual Exclusion with Read/Write Variables1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
Process Synchronization CS 502 Spring 99 WPI MetroWest/Southboro Campus.
The Critical-Section Problem
Operating Systems Unit 3: – Concurrent execution mutual exclusion – Concurrent programming semaphore monitor Operating Systems.
1 Course Syllabus 1. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation.
1 Tuesday, June 20, 2006 "The box said that I needed to have Windows 98 or better... so I installed Linux." - LinuxNewbie.org.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Bakery Algorithm - Proof
Concurrency in Distributed Systems: Mutual exclusion.
Process Synchronization Topics: 1.Background 2.The critical-section problem 3.Semaphores 4.Critical Regions 5.Monitors Topics: 1.Background 2.The critical-section.
The Critical Section Problem
1 Synchronization (1) Dave Eckhardt
28/10/1999POS-A1 The Synchronization Problem Synchronization problems occur because –multiple processes or threads want to share data; –the executions.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Silberschatz and Galvin  Operating System Concepts Module 6: Process Synchronization Background The Critical-Section Problem Synchronization.
1 Chapter 10 Distributed Algorithms. 2 Chapter Content This and the next two chapters present algorithms designed for loosely-connected distributed systems.
Principles of Operating Systems Lecture 6 and 7 - Process Synchronization.
3.1. Concurrency, Critical Sections, Semaphores
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 7 Process Synchronization Slide 1 Chapter 7 Process Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Process Synchronization Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the.
1 Concurrent Processes. 2 Cooperating Processes  Operating systems allow for the creation and concurrent execution of multiple processes  concurrency.
CSCI-375 Operating Systems Lecture Note: Many slides and/or pictures in the following are adapted from: slides ©2005 Silberschatz, Galvin, and Gagne Some.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally INTERPROCESS COMMUNICATION AND SYNCHRONIZATION SYNCHRONIZATION.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Bakery Algorithm - Proof
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Chapter 7: Process Synchronization
Chapter 6-7: Process Synchronization
Chapter 5: Process Synchronization
ICS 143 Principles of Operating Systems
Part II: Process Management Chapter 7 Process Synchronization
Lecture 25 Syed Mansoor Sarwar
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Lecture 22 Syed Mansoor Sarwar
The Critical-Section Problem
Lecture 19 Syed Mansoor Sarwar
Introduction to Cooperating Processes
Chapter 5: Process Synchronization
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Lecture 2 Part 2 Process Synchronization
Critical section problem
Lecture 29 Syed Mansoor Sarwar
Lecture 28 Syed Mansoor Sarwar
Grades.
Chapter 6: Process Synchronization
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Multiprocessor Synchronization Algorithms ( )
Lecture 18 Syed Mansoor Sarwar
Lecture 27 Syed Mansoor Sarwar
Lecture 21 Syed Mansoor Sarwar
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Chapter 6: Synchronization Tools
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Chapter 6 Process Synchronization
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Syllabus 1. Introduction - History; Views; Concepts; Structure
Operating Systems {week 10}
Presentation transcript:

Lecture 20 Syed Mansoor Sarwar Operating Systems Lecture 20 Syed Mansoor Sarwar

© Copyright Virtual University of Pakistan Agenda for Today Review of previous lecture 2-Process Critical Section Problem (continued) n-Process Critical Section Problem The Bakery Algorithm Recap of lecture 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Review of Lecture 19 Process Synchronization The Critical Section Problem 2-Process Critical Section Problem Solutions 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Algorithm 3 Combined shared variables of algorithms 1 and 2. boolean flag[2]; // Set to false int turn=0; 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Algorithm 3 Process Pi do { critical section remainder section } while (1); flag[i] = true; turn = j; while (flag[j] && turn == j) ; flag[i] = false; 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Algorithm 3 Meets all three requirements: Mutual Exclusion: ‘turn’ can have one value at a given time (0 or 1) Bounded-waiting: At most one entry by a process and then the second process enters into its CS 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Algorithm 3 Progress: Exiting process sets its ‘flag’ to false … comes back quickly and set it to true again … but sets turn to the number of the other process 8 December 2018 © Copyright Virtual University of Pakistan

n-Process Critical Section Problem Consider a system of n processes (P0, P1 ... Pn-1). Each process has a segment of code called a critical section in which the process may change shared data. 8 December 2018 © Copyright Virtual University of Pakistan

n-Process Critical Section Problem When one process is executing its critical section, no other process is allowed to execute in its critical section. The critical section problem is to design a protocol to serialize executions of critical sections. 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm By Leslie Lamport Before entering its critical section, process receives a ticket number. Holder of the smallest ticket number enters the critical section. If processes Pi and Pj receive the same number, if i < j, then Pi is served first; else Pj is served first. 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm The ticket numbering scheme always generates numbers in the increasing order of enumeration; i.e., 1, 2, 3, 4, 5 ... 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm Notations (ticket #, process id #) (a,b) < (c,d) if a < c or if a == c and b < d max (a0,…, an-1) is a number, k, such that k  ai for i = 0, …, n–1 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm Data Structures boolean choosing[n]; int number[n]; These data structures are initialized to false and 0, respectively 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm Structure of Pi do { choosing[i] = true; number[i] = max(number[0], number[1], …, number [n – 1]) + 1; choosing[i] = false; 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm Critical Section for (j = 0; j < n; j++) { while (choosing[j]) ; while ( (number[j] != 0) && ((number[j], j) < (number[i], i)) ) ; } 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm remainder section } while (1); number[i] = 0; 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm Process Number P0 3 P1 P2 7 P3 4 P4 8 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm P0 P2 P3 P4 (3,0) < (3,0) (3,0) < (7,2) (3,0) < (4,3) (3,0) < (8,4) Number[1] = 0 (7,2) < (3,0) (7,2) < (7,2) (7,2) < (4,3) (7,2) < (8,4) (4,3) < (3,0) (4,3) < (7,2) (4,3) < (4,3) (4,3) < (8,4) (8,4) < (3,0) (8,4) < (7,2) (8,4) < (4,3) (8,4) < (8,4) 8 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Recap of Lecture n-Process Critical Section Problem The Bakery Algorithm 8 December 2018 © Copyright Virtual University of Pakistan

Lecture 20 Syed Mansoor Sarwar Operating Systems Lecture 20 Syed Mansoor Sarwar