1 Tuesday, June 20, 2006 "The box said that I needed to have Windows 98 or better... so I installed Linux." - LinuxNewbie.org.

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
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
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.
China’s Software Industry August 2006 Instructor: Hengming Zou, Ph.D.
Silberschatz, Galvin and Gagne  Operating System Concepts Background Shared-memory solution to bounded-buffer problem allows at most n – 1 items.
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.
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.
1 Chapter 7: Process Synchronization 2 Contents Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Module 6: Synchronization 6.1 Background 6.2 The Critical-Section.
Process Synchronization Topics: 1.Background 2.The critical-section problem 3.Semaphores 4.Critical Regions 5.Monitors Topics: 1.Background 2.The critical-section.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Modified by Dr M A Berbar Chapter 6: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
The Critical Section Problem
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.
Silberschatz and Galvin  Operating System Concepts Module 6: Process Synchronization Background The Critical-Section Problem Synchronization.
Principles of Operating Systems Lecture 6 and 7 - Process Synchronization.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
3.1. Concurrency, Critical Sections, Semaphores
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
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.
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.
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.
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.
Synchronicity Introduction to Operating Systems: Module 5.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
7.1 Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Process Synchronization
Chapter 5: Process Synchronization
Chapter 7: Process Synchronization
Chapter 6-7: Process Synchronization
Chapter 5: Process Synchronization
ICS 143 Principles of Operating Systems
Topic 6 (Textbook - Chapter 5) Process Synchronization
The Critical-Section Problem
Introduction to Cooperating Processes
Chapter 5: Process Synchronization
Lecture 20 Syed Mansoor Sarwar
Lecture 2 Part 2 Process Synchronization
Grades.
Chapter 6: Process Synchronization
Lecture 21 Syed Mansoor Sarwar
Chapter 6: Synchronization Tools
Chapter 6 Process Synchronization
CSE 542: Operating Systems
Presentation transcript:

1 Tuesday, June 20, 2006 "The box said that I needed to have Windows 98 or better... so I installed Linux." - LinuxNewbie.org

2 6 th Edition §Skip 1.4, 1.5, 1.6 §Skip 2.6 §Skip 3.6, 3.7, 3.8 l (3.5 will be done later) §Skip 4.5, 4.6 §Skip 6.4, 6.5

3 §Producer / Consumer §Critical Section problem

4 The Critical-Section Problem §n processes all competing to use some shared data §Each process has a code segment, called critical section, in which the shared data is accessed. §Problem – ensure that when one process is executing in its critical section, no other process is allowed to execute in its critical section.

5 §Race condition: The situation where several processes access – and manipulate shared data concurrently. The final value of the shared data depends upon which process finishes last.

6 Solution to Critical-Section Problem 1.Mutual Exclusion. 2.Progress. 3.Bounded Waiting.

7 Algorithm 1 turn is initialized to 0 (or 1)

8 §Algorithm 1 §Strict Alternation §Other problems with Algorithm 1?...

9 Algorithm 2 §Shared variables l boolean flag[2]; initially flag [0] = flag [1] = false. l flag [i] = true  P i ready to enter its critical section

10 Algorithm 2 § i, j two processes j=1-i §Process P i do { flag[i] := true; while (flag[j]) ; critical section flag [i] = false; remainder section } while (1);

11 Algorithm 2 §Process P 0 do { flag[0] := true; while (flag[1]) ; critical section flag [0] = false; remainder section } while (1); §Process P 1 do { flag[1] := true; while (flag[0]) ; critical section flag [1] = false; remainder section } while (1);

12 Algorithm 2 §Problems?

13 Algorithm 3 §Process P i do { flag [i]:= true; turn = j; while (flag [j] and turn = j) ; critical section flag [i] = false; remainder section } while (1);

14 Algorithm 3 §Process P 0 do { flag [0]:= true; turn = 1; while (flag [1] and turn = 1) ; critical section flag [0] = false; remainder section } while (1); §Process P 1 do { flag [1]:= true; turn = 0; while (flag [0] and turn = 0) ; critical section flag [1] = false; remainder section } while (1);

15 Algorithm 3 §Meets all three requirements; solves the critical-section problem for two processes.

16 Bakery Algorithm §Before entering its critical section, process receives a number. Holder of the smallest number enters the critical section. §If processes P i and P j receive the same number, if i < j, then P i is served first; else P j is served first. §The numbering scheme always generates numbers in increasing order of enumeration; i.e., 1,2,3,3,3,3,4,5... Critical section for n processes

17 Bakery Algorithm §Notation <  lexicographical order (ticket #, process id #) l (a,b) < c,d) if a < c or if a = c and b < d l max (a 0,…, a n-1 ) is a number, k, such that k  a i for i - 0, …, n – 1 §Shared data boolean choosing[n]; int number[n]; Data structures are initialized to false and 0 respectively

18 Bakery Algorithm do { choosing[i] = true; number[i] = max(number[0], number[1], …, number [n – 1])+1; choosing[i] = false; for (j = 0; j < n; j++) { while (choosing[j]) ; while ((number[j] != 0) && (number[j],j) < (number[i],i) ) ; } critical section number[i] = 0; //exit section remainder section } while (1);

19 Synchronization Hardware §One way … disable interrupts §problems?

20 Synchronization Hardware §One way … disable interrupts §What problems can occur if we use the following implementation of a lock? Lock::Acquire { disable_interrupts(); } (critical section) Lock::Release { enable_interrupts(); }

21 TestAndndSet Instruction boolean TestAndSet (boolean *target) { boolean rv = *target; *target = TRUE; return rv: }

22 Mutual Exclusion with Test-and-Set §Shared data: boolean lock = false; Process P i do { while (TestAndSet(lock)) ; critical section lock = false; remainder section } What if two processes try to execute TestAndSet?

23 Synchronization Hardware Any problems with test and set?

24 §Can a context switch occur if a process is executing in its critical section?

25 Synchronization Hardware Do yourself §Swap §Mutual exclusion with test and set

26 §Drawback of all of the synchronization solutions seen so far?

27 BUSY WAITING A process is waiting for an event to occur and it does so by executing instructions

28 §Busy Waiting §Priority inversion problem §A lock that uses busy waiting is called a spinlock §Synchronization tool that allow a process to block instead of wasting CPU time, when the process is not allowed to enter its critical region.