Lecture 21 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.
Previously… Processes –Process States –Context Switching –Process Queues Threads –Thread Mappings Scheduling –FCFS –SJF –Priority scheduling –Round Robin.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
The Critical-Section Problem
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.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Module 6: Synchronization 6.1 Background 6.2 The Critical-Section.
Synchronization (other solutions …). Announcements Assignment 2 is graded Project 1 is due today.
Synchronization Solutions
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
The Critical Section Problem
1 Synchronization (1) Dave Eckhardt
Concurrency, Mutual Exclusion and Synchronization.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Principles of Operating Systems Lecture 6 and 7 - Process Synchronization.
3.1. Concurrency, Critical Sections, Semaphores
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
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.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process 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 5: Process Synchronization
Chapter 5: Process Synchronization
Chapter 7: Process Synchronization
Chapter 6-7: Process Synchronization
Chapter 5: Process Synchronization
Chapter 6: Process Synchronization
ICS 143 Principles of Operating Systems
Topic 6 (Textbook - Chapter 5) Process Synchronization
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Lecture 22 Syed Mansoor Sarwar
The Critical-Section Problem
Lecture 19 Syed Mansoor Sarwar
Introduction to Cooperating Processes
Module 7a: Classic Synchronization
Chapter 5: Process Synchronization
Lecture 20 Syed Mansoor Sarwar
Critical Sections User Software Solutions Dekker’s Algorithm
Lecture 2 Part 2 Process Synchronization
Critical section problem
Lecture 29 Syed Mansoor Sarwar
Lecture 28 Syed Mansoor Sarwar
Grades.
Chapter 6: Process Synchronization
Lecture 27 Syed Mansoor Sarwar
Chapter 6: Synchronization Tools
Chapter 6 Process Synchronization
Process/Thread Synchronization (Part 2)
Presentation transcript:

Lecture 21 Syed Mansoor Sarwar Operating Systems Lecture 21 Syed Mansoor Sarwar

© Copyright Virtual University of Pakistan Agenda for Today Review of previous lecture 2-Process CS problem solution N-Process CS problem The Bakery Algorithm Hardware solutions Recap of lecture 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Review of Lecture 20 2-Process Critical Section Problem Solution n-Process Critical Section Problem The Bakery Algorithm 8 April 2019 © 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 April 2019 © 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 April 2019 © Copyright Virtual University of Pakistan

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

© Copyright Virtual University of Pakistan Bakery Algorithm Process Number P0 3 P1 P2 7 P3 4 P4 8 8 April 2019 © 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 April 2019 © Copyright Virtual University of Pakistan 1 3 2 4

© Copyright Virtual University of Pakistan Bakery Algorithm P1 not interested to get into its critical section  number[1] is 0 P2, P3, and P4 wait for P0 P0 gets into its CS, get out, and sets its number to 0 P3 get into its CS and P2 and P4 wait for it to get out of its CS 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm P2 gets into its CS and P4 waits for it to get out P4 gets into its CS Sequence of execution of processes: <P0, P3, P2, P4> 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm Meets all three requirements: Mutual Exclusion: (number[j], j) < (number[i], i) cannot be true for both Pi and Pj Bounded-waiting: At most one entry by each process (n-1 processes) and then a requesting process enters its critical section (First-Come-First-Serve) 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Bakery Algorithm Progress: Decision takes complete execution of the ‘for loop’ by one process No process in its ‘Remainder Section’ (with its number set to 0) participates in the decision making 8 April 2019 © Copyright Virtual University of Pakistan

Synchronization Hardware Normally, access to a memory location excludes other accesses to that same location. Extension: designers have proposed machine instructions that perform two operations atomically (indivisibly) on the same memory location (e.g., reading and writing). 8 April 2019 © Copyright Virtual University of Pakistan

Synchronization Hardware The execution of such an instruction is also mutually exclusive (even on Multiprocessors). They can be used to provide mutual exclusion but other mechanisms are needed to satisfy the other two requirements of a good solution to the CS problem. 8 April 2019 © Copyright Virtual University of Pakistan

Test-And-Set (TSL) Instruction Test and modify a word atomically. boolean TestAndSet(boolean &target) { boolean rv = target; target = true; return rv; } 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Solution with TSL Structure for Pi (‘lock’ is set to false) do { while ( TestAndSet(lock) ) ; Critical Section lock = false; Remainder Section 8 April 2019 } © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Solution with TSL Is the TSL-based solution good? No Mutual Exclusion: Satisfied Progress: Satisfied Bounded Waiting: Not satisfied 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Swap Instruction Swaps two variables atomically void swap (boolean &a, boolean &b) { boolean temp = a; a = b; b = temp; } 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Solution with Swap Structure for Pi ‘key’ is local and set to false do { key = true; while (key == true) swap(lock,key); Critical Section lock = false; Remainder Section } 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Solution with swap Is the swap-based solution good? No Mutual Exclusion: Satisfied Progress: Satisfied Bounded Waiting: Not satisfied 8 April 2019 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Recap of Lecture The Bakery algorithm Synchronization hardware The test-and-set and swap instructions Solutions based on the TSL and swap instructions 8 April 2019 © Copyright Virtual University of Pakistan

Lecture 21 Syed Mansoor Sarwar Operating Systems Lecture 21 Syed Mansoor Sarwar