Process Synchronization - I

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

Synchronization and Deadlocks
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
1 Implementations: User-level Kernel-level User-level threads package each u.process defines its own thread policies! flexible mgt, scheduling etc…kernel.
May 23, 2002Serguei A. Mokhov, 1 Synchronization COMP346/ Operating Systems Tutorial 3 Revision 1.2 October 7, 2003.
Chapter 2 Processes and Threads
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.
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.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
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.
Interprocess Communication
Cpr E 308 Spring 2004 Recap for Midterm Introductory Material What belongs in the OS, what doesn’t? Basic Understanding of Hardware, Memory Hierarchy.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Concurrency.
EEE 435 Principles of Operating Systems Interprocess Communication Pt I (Modern Operating Systems 2.3)
1 Course Syllabus 1. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation.
Interprocess Communication
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Outline Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Process Synchronization Ch. 4.4 – Cooperating Processes Ch. 7 – Concurrency.
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.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
Mutual Exclusion. Readings r Silbershatz: Chapter 6.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Concurrency in Shared Memory Systems Synchronization and Mutual Exclusion.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 Processes and Threads Part II Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Interprocess Communication Race Conditions
CSE 120 Principles of Operating
Chapter 5: Process Synchronization
143a discussion session week 3
Lecture 12: Peterson’s Solution and Hardware Support
Topic 6 (Textbook - Chapter 5) Process Synchronization
Lecture 19 Syed Mansoor Sarwar
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Lecture 2 Part 2 Process Synchronization
Critical section problem
Grades.
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 6: Process Synchronization
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Lecture 12: Peterson’s Solution and Hardware Support
CSE 451: Operating Systems Autumn 2004 Module 6 Synchronization
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2004 Module 6 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Syllabus 1. Introduction - History; Views; Concepts; Structure
Presentation transcript:

Process Synchronization - I CS 3305 Process Synchronization - I Lecture 11

Process Synchronization Race Condition Critical Section Mutual Exclusion Peterson’s Solution Disabling Interrupts Test and Lock Instruction (TSL) Semaphores Deadlock

Race Condition Example (1) Assume a spooler directory array (in shared memory) has a number of slots Numbered 0, 1, 2… Each slot has a file name Two other variables: In points to the first empty slot where a new filename can be entered. Out points to the first non-empty slot, from where the spooler will read a filename and print the corresponding file.

Race Condition Example (1) Spooler Directory Slots 1,2,3 are empty indicating the files in those slots have printed Each process has a local variable next_free_slot representing an empty slot Assume both process A and B want to print files. Each wants to enter the filename into the first empty slot in spooler directory 1 Process A next_free_slot variable 2 OUT 3 4 4 Test.txt 5 Prog.c IN 6 Prog.h 7 7 8 Process B next_free_slot variable …

Race Condition Example (1) Spooler Directory Process A reads IN and stores the value 7 in its local variable, next_free_slot Process A’s time quanta expires Process B is picked as the next process to run 1 Process A next_free_slot variable 2 OUT 3 4 4 Talk.exe 5 Prog.c IN 6 Prog.h 7 7 8 Process B next_free_slot variable …

Race Condition Example (1) Spooler Directory Process B reads IN and stores the value 7 in its local variable, next_free_slot Process B writes a filename to slot 7 1 Process A next_free_slot variable 2 OUT 3 4 4 Talk.exe 5 Prog.c IN 6 Prog.h 7 7 ProgB.c 8 Process B next_free_slot variable …

Race Condition Example (1) Spooler Directory Process B then updates the In variable to 8 Process A now gets control of the CPU 1 Process A next_free_slot variable 2 OUT 3 4 4 Talk.exe 5 Prog.c IN 6 Prog.h 8 7 ProgB.c 8 Process B next_free_slot variable …

Race Condition Example (1) Spooler Directory Process A writes its filename to slot 7 which erases process B’s filename. Process B does not get its file printed. 1 2 OUT 3 4 Process A 4 Talk.exe 5 Prog.c IN 6 Prog.h 8 7 ProgA.c 8 Process B …

Race Condition (2) Application: Withdraw money from a bank account Two requests for withdrawal from the same account comes to a bank from two different ATM machines A thread for each request is created Assume a balance of $1000

Race Condition (2) bank_example (account, amount_to_withdraw) { 1. balance = get_balance(account); 2. if (balance => amount_to_withdraw) withdraw_authorized(); else withdraw_request_denied() 3. balance = balance – amount_to_withdraw; } What happens if both requests request that $600 be withdrawn?

Race Condition (2) Process / Thread 1 Process / Thread 2 1. Read balance: $1000 2. Withdraw authorized for $600 (now actual balance is $400) CPU switches to process 2 3. Read Balance $1000 4. Withdraw authorized for $600 (this is unreal!!) 5. Update balance $1000-$600 = $400  CPU switches to process 1 6. Update balance $1000-$600 = $400

Critical Sections and Mutual Exclusion A critical section is any piece of code that accesses shared data Printer example: In, Out variables are shared Bank account: Balance is shared Mutual exclusion ensures that only one thread/process accesses the critical section at a time i.e., No two processes simultaneously in critical section!

Mutual Exclusion in Critical Sections

General structure for Mutual Exclusion Do { entry section critical section exit section remainder section } while(1)