Syllabus 1. Introduction - History; Views; Concepts; Structure

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Mutual Exclusion – SW & HW By Oded Regev. Outline: Short review on the Bakery algorithm Short review on the Bakery algorithm Black & White Algorithm Black.
Operating Systems Part III: Process Management (Process Synchronization)
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
1 Chapter 2 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2007 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld.
Chapter 6: Process Synchronization
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.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Mutual Exclusion.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
1 Course Syllabus 1. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation.
1 Chapter 3 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2014 Synchronization Algorithms and Concurrent Programming Synchronization.
CPSC 668Set 7: Mutual Exclusion with Read/Write Variables1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
Multiprocess Synchronization Algorithms ( )
1 Operating Systems, 112 Practical Session 5, Synchronization 1.
The Critical-Section Problem
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.
Concurrency in Distributed Systems: Mutual exclusion.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Concurrency 1 CS502 Spring 2006 Thought experiment static int y = 0; int main(int argc, char **argv) { extern int y; y = y + 1; return 0; }
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.
1 Lecture 9: Synchronization  concurrency examples and the need for synchronization  definition of mutual exclusion (MX)  programming solutions for.
The Critical Section Problem
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
THIRD PART Algorithms for Concurrent Distributed Systems: The Mutual Exclusion problem.
3.1. Concurrency, Critical Sections, Semaphores
Mutual Exclusion Using Atomic Registers Lecturer: Netanel Dahan Instructor: Prof. Yehuda Afek B.Sc. Seminar on Distributed Computation Tel-Aviv University.
1 Chapter 2 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2014 Synchronization Algorithms and Concurrent Programming Synchronization.
Process Synchronization Tanenbaum Ch 2.3, 2.5 Silberschatz Ch 6.
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.
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.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
1 Course Syllabus 1. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation.
Bakery Algorithm - Proof
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Chapter 6-7: Process Synchronization
Chapter 5: Process Synchronization
Process Synchronization - I
Concurrent Distributed Systems
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Lecture 22 Syed Mansoor Sarwar
The Critical-Section Problem
Introduction to Cooperating Processes
Module 7a: Classic Synchronization
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Lecture 20 Syed Mansoor Sarwar
Lecture 2 Part 2 Process Synchronization
Practical Session 5, Synchronization
Grades.
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Multiprocessor Synchronization Algorithms ( )
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
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Process/Thread Synchronization (Part 2)
Presentation transcript:

Syllabus 1. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation of Processes 3. Scheduling – Paradigms; Unix; Modeling 4. Synchronization – Mutual exclusion, semaphores, monitors 5. Memory Management - Virtual memory; Page replacement algorithms; Segmentation 6. File Systems - Implementation; Directory and space management; Unix file system; Distributed file systems (NFS) 7. Security - buffer overflow attack, hardware security, access control models, access control in UNIX. 8. Virtualization – Virtual machines, type I and II hypervisors, classic virtualization, sensitive and privileged instructions, binary translation, memory virtualization Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Mutual exclusion: motivation Race Conditions: Example: Spooler directory with slots; index variables; two processes attempt concurrent access. In points to the next empty slot, Out points to entry holding name of file to print next. Process A 4 5 6 7 . . . . . . abc.doc f.ps paper.ps In=7 Process B Out = 4 Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Code using reads/writes only Add-file-to-print-spool (char *name) Local-in := In StoreName(Spool-dir[local-in], name) In := (local-in+1) mod DIR-LEN A scenario proving the above code wrong Process A performs line 1 Process A is preempted by Process B Process B performs Add-file-to-print-spool to completion Process A is re-scheduled, completes lines 2-3. Process B's file is never printed. Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

The mutual exclusion problem (Dijkstra, 1965) How can we avoid such race conditions? We need to devise a protocol that guarantees mutually exclusive access by processes to a shared resource (such as a file, printer, etc.) or, more generally, a critical section of code Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

The problem model Multiple processes Processes can apply read, write, or stronger operations to shared memory Completely asynchronous We assume processes do not fail-stop Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Mutual exclusion: formal definition loop forever Remainder code Entry code Critical section (CS) Exit code end loop Remainder code Entry code CS Exit code Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Mutex Requirements Mutual exclusion: No two processes are at the critical section (CS) at the same time Deadlock-freedom: If processes are trying to enter their critical section, then some process eventually enters the critical section Starvation-freedom: If a process is trying to enter its critical section, then this process must eventually enter its critical section Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Mutual exclusion using critical regions Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Brute force solution: disabling interrupts Disable interrupts Do your stuff Enable interrupts Problems User processes are not allowed to disable interrupts Disabling interrupts must be done for a very short period of time Does not solve the problem in a multi-processor system Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

2-process Mutual Exclusion with a lock variable initially: lock=0 await c: repeatedly evaluate condition c until true Program for both processes await lock=0 lock:=1 CS lock:=0 No Does the algorithm satisfy mutex? Does it satisfy deadlock-freedom? Does it satisfy starvation-freedom? Yes No Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Mutual Exclusion: strict alternation initially: turn=0 Program for process 0 await turn=0 CS turn:=1 Program for process 1 await turn=1 CS turn:=0 Yes Does the algorithm satisfy mutex? Does it satisfy deadlock-freedom? Does it satisfy starvation-freedom? No No Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Mutual Exclusion: flag array bool flags[2] initially {false, false} Program for process 0 flags[0]:=true await flags[1]=false CS flags[0]:=false Program for process 1 flags[1]:=true await flags[0]=false CS flags[1]:=false Yes Does the algorithm satisfy mutex? Does it satisfy deadlock-freedom? Does it satisfy starvation-freedom? No No Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Peterson’s 2-process algorithm (Peterson, 1981) initially: b[0]:=false, b[1]:=false, initial value of turn immaterial Program for process 0 b[0]:=true turn:=0 await (b[1]=false or turn=1) CS b[0]:=false Program for process 1 b[1]:=true turn:=1 await (b[0]=false or turn=0) CS b[1]:=false Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Schema for Peterson’s 2-process algorithm Indicate participation b[i]:=true Barrier turn:=i no, maybe Is there contention? b[1-i]=true? yes First to cross barrier? turn=1-i? no yes Critical Section Exit code b[i]:=false Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky Synchronization Algorithms and Concurrent Programming , Gadi Taubenfeld © 2006

Peterson’s 2-process algorithm satisfies both mutual-exclusion and starvation-freedom Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Mutual exclusion for n processes: A tournament tree Level 2 1 2 3 4 5 6 7 Level 1 Level 0 Processes A tree-node is identified by: [level, node#] Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky Synchronization Algorithms and Concurrent Programming , Gadi Taubenfeld © 2006

N-process mutual exclusion: a tournament tree Variables Per node: b[level, 2node], b[level, 2node+1], turn[level,node] Per process (local): level, node, id. Program for process i node:=i For level = 0 to log n-1 do id:=node mod 2 node:= node/2 b[level,2node+id]:=true turn[level,node]:=id await (b[level,2node+1-id]=false or turn[level,node]=1-id) end do CS for level=log n –1 downto 0 do node:=  i/2level b[level,2node+id]:=false // id is value set at this node in entry Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Fairness: First in First Out (FIFO) Mutual Exclusion Deadlock-freedom Starvation-freedom remainder doorway waiting entry code critical section exit code FIFO: if process p is waiting and process q has not yet started the doorway, then q will not enter the CS before p Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky Synchronization Algorithms and Concurrent Programming , Gadi Taubenfeld © 2006

Lamport’s Bakery Algorithm 1 2 3 4 5 n remainder 1 3 2 2 4 doorway entry waiting 1 3 2 4 2 1 2 2 CS time 1 2 2 exit Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky Synchronization Algorithms and Concurrent Programming , Gadi Taubenfeld © 2006

Implementation 1 code of process i , i  {1 ,..., n} number[i] := 1 + max {number[j] | (1  j  n)} for j := 1 to n (<> i) { await (number[j] = 0)  (number[j] > number[i]) } critical section number[i] := 0 1 2 3 4 n number integer Does this implementation work? Answer: No, it can deadlock! Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky Synchronization Algorithms and Concurrent Programming , Gadi Taubenfeld © 2006

Implementation 1: deadlock 2 3 4 5 n remainder 1 2 2 doorway entry waiting 1 2 2 1 deadlock CS time 1 exit Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky Synchronization Algorithms and Concurrent Programming , Gadi Taubenfeld © 2006

Implementation 2 code of process i , i  {1 ,..., n} number[i] := 1 + max {number[j] | (1  j  n)} for j := 1 to n (<> i) { await (number[j] = 0)  (number[j],j) < number[i],i) // lexicographical order } critical section number[i] := 0 1 2 3 4 n number integer Does this implementation work? Answer: It does not satisfy mutual exclusion! Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky Synchronization Algorithms and Concurrent Programming , Gadi Taubenfeld © 2006

Implementation 2: no mutual exclusion 1 2 3 4 5 n remainder 1 2 2 doorway entry waiting 1 2 2 1 2 2 CS time 1 exit Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky Synchronization Algorithms and Concurrent Programming , Gadi Taubenfeld © 2006

The Bakery Algorithm code of process i, i  {1 ,..., n} 1: choosing[i] := true 2: number[i] := 1 + max {number[j] | (1  j  n)} 3: choosing[i] := false 4: for j := 1 to n do 5: await choosing[j] = false 6: await (number[j] = 0)  (number[j],j)  (number[i],i) 7: od 8: critical section 9: number[i] := 0 Doorway Waiting Bakery 1 2 3 4 n choosing false false false false false false bits number integer Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Lamport’s bakery algorithm satisfies mutual-exclusion, starvation-freedom, and FIFO Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

The test-and-set instruction initially: v:=0 Test-and-set(w) do atomically prev:=w w:=1 return prev Program for process i await test&set(v) = 0 Critical Section v:=0 Mutual exclusion? Yes Deadlock-freedom? Yes Starvation-freedom? No Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky

Starvation-free mutex using test-and-set boolean lock initially 0, interested[n] initially false program for process i interested[i]:=true await ( (test-and-set(lock) = 0) || (interested[i]=false) ) CS interested[i]:=false j:=(i+1) % n while (j != i && !interested[j]) j:=++j % n if (j=i) lock:=0 else interested[j]:=false Operating Systems, Spring 2019, I. Dinur , D. Hendler and M. Kogan-Sadetsky