Lecture 22 Syed Mansoor Sarwar

Slides:



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

Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Previously… Processes –Process States –Context Switching –Process Queues Threads –Thread Mappings Scheduling –FCFS –SJF –Priority scheduling –Round Robin.
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.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
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.
Process Synchronization
Chapter 2.3 : Interprocess Communication
Synchronization Solutions
Process Synchronization Topics: 1.Background 2.The critical-section problem 3.Semaphores 4.Critical Regions 5.Monitors Topics: 1.Background 2.The critical-section.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
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.
Principles of Operating Systems Lecture 6 and 7 - Process Synchronization.
Operating Systems CSE 411 CPU Management Oct Lecture 14 Instructor: Bhuvan Urgaonkar.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
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.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Process Synchronization Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
Process Synchronization
Chapter 5: Process Synchronization
Process Synchronization: Semaphores
Background on the need for Synchronization
Process Synchronization
Chapter 5: Process Synchronization
Chapter 6-7: Process Synchronization
Chapter 5: Process Synchronization
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization
Process Synchronization
Chapter 6: Synchronization Tools
Chapter 6: Synchronization Tools
Lecture 25 Syed Mansoor Sarwar
Topic 6 (Textbook - Chapter 5) Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Lecture 19 Syed Mansoor Sarwar
Module 7a: Classic 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
Chapter 6: Process Synchronization
Chapter 6: Synchronization Tools
Lecture 21 Syed Mansoor Sarwar
Chapter 5: Process Synchronization
Chapter 6: Synchronization Tools
, Part II Process Synchronization
Process Synchronization
Chapter 6 Process Synchronization
Process Synchronization
Process/Thread Synchronization (Part 2)
Presentation transcript:

Lecture 22 Syed Mansoor Sarwar Operating Systems Lecture 22 Syed Mansoor Sarwar

© Copyright Virtual University of Pakistan Agenda for Today Review of previous lecture Semaphores based solutions for the critical section problem Deadlock and starvation Binary and counting semaphores Recap of lecture 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Review of Lecture 21 The Bakery algorithm Hardware based solutions 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan A Good Solution ‘key’ local; ‘lock’ and ‘waiting’ global All variables set to false do { waiting[i] = true; key = true; while (waiting[i] && key) key = TestAndSet(lock); waiting[i] = false; 7 December 2018 Critical Section © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan A Good Solution j = (i+1) % n; while ( (j != i) && !waiting[j] ) j = (j+1) % n; if (j == i) lock = false; else waiting[j] = false; Remainder Section } 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Solution with Test-And-Set Is the given solution good? Yes Mutual Exclusion: Satisfied Progress: Satisfied Bounded Waiting: Satisfied 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Semaphores 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Semaphores Synchronization tool Available in operating systems Semaphore S – integer variable that can only be accessed via two indivisible (atomic) operations, called wait and signal 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Semaphores wait(S){ while S 0 ; //no-op S--; } signal(S){ S++; 7 December 2018 © Copyright Virtual University of Pakistan

n-Processes CS Problem Shared data: semaphore mutex = 1; Structure of Pi: do { critical section remainder section } while (1); wait(mutex); signal(mutex); 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Is it a Good Solution? Mutual Exclusion: Yes Progress: Yes Bounded Waiting: No 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Atomic Execution Uni-Processor Environment Inhibit interrupts before executing code for wait() and signal() Bus-based Multi-Processor Environment Lock the data bus Use a software solution 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Busy Waiting Processes wait by executing CPU instructions Problem? Wasted CPU cycles Solution? Modify the definition of semaphore 7 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Recap of Lecture Synchronization hardware Semaphores Semaphore based solutions for the critical section problem Busy waiting and modified definition of semaphore 7 December 2018 © Copyright Virtual University of Pakistan

Lecture 22 Syed Mansoor Sarwar Operating Systems Lecture 22 Syed Mansoor Sarwar