Critical Sections User Software Solutions Dekker’s Algorithm

Slides:



Advertisements
Similar presentations
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
 Read about Therac-25 at  [  [
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
CSC321 Concurrent Programming: §3 The Mutual Exclusion Problem 1 Section 3 The Mutual Exclusion Problem.
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.
Concurrent Programming Problems OS Spring Concurrency pros and cons Concurrency is good for users –One of the reasons for multiprogramming Working.
Concurrency: Mutual Exclusion and Synchronization - Chapter 5 (Part 2)
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.
Concurrent Programming James Adkison 02/28/2008. What is concurrency? “happens-before relation – A happens before B if A and B belong to the same process.
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.
Intertask Communication and Synchronization In this context, the terms “task” and “process” are used interchangeably.
Chapter 3 The Critical Section Problem
Concurrency.
The Critical-Section Problem
Shared Memory Coordination We will be looking at process coordination using shared memory and busy waiting. –So we don't send messages but read and write.
1 Tuesday, June 20, 2006 "The box said that I needed to have Windows 98 or better... so I installed Linux." - LinuxNewbie.org.
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.
University of Pennsylvania 9/19/00CSE 3801 Concurrent Processes CSE 380 Lecture Note 4 Insup Lee.
Synchronization (other solutions …). Announcements Assignment 2 is graded Project 1 is due today.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other.
Synchronization CSCI 444/544 Operating Systems Fall 2008.
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.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
The Critical Section Problem
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.
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.
1 Concurrency: Mutual Exclusion and Synchronization Module 2.2.
3.1. Concurrency, Critical Sections, Semaphores
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
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.
1 Lecture 8: Concurrency: Mutual Exclusion and Synchronization Advanced Operating System Fall 2012.
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.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Process Synchronization I CPE Operating Systems
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Synchronization Mutual Exclusion Solutions using shared variables + problems such as deadlocks, starvation, progressiveness, busy wait Prof. R K Joshi.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Process Synchronization: Semaphores
Designing Parallel Algorithms (Synchronization)
Lecture 22 Syed Mansoor Sarwar
The Critical-Section Problem
Lecture 2 Part 2 Process Synchronization
Critical section problem
Grades.
Chapter 6: Process Synchronization
Lecture 21 Syed Mansoor Sarwar
Chapter 6: Synchronization Tools
CIS 720 Lecture 5.
Process/Thread Synchronization (Part 2)
CSE 542: Operating Systems
Don Porter Portions courtesy Emmett Witchel
Presentation transcript:

Critical Sections User Software Solutions Dekker’s Algorithm Peterson’s Algorithm Hardware Test-and-Set

Critical Section When a process is accessing shared modifiable data or a resource that can only operate on behalf of one process at a time, the process is said to be in a critical section. When one process is in a critical section, all other processes (at least those that access the shared modifiable data and/or resource) are excluded from their critical section.

Requirements for Solving the CS issue Mutual Exclusion. If a process is executing in it’s Critical Section, then no other process can execute in it’s Critical Section. Progress. When no process is in a critical section, any process that requests entry to the critical section must be permitted to enter without delay. Bounded Wait. There is an upper bound on the number of times a process can enter it’s critical sections while another is waiting (a.k.a no starvation)

Software Solution Attempt 1   Comments: This method insures Mutual Exclusion, however, processone must go first and processone and processtwo must alternate. This method causes busy waiting. (i.e. the use of the CPU to loop, waiting for the condition variable to change). void processOne(void) { while (1) while (processNumber == 2) {// stall} Critical Section processNumber = 2; Other Stuff }

Software Solution Attempt 2   Comments: This method allows processes to execute without alternating. If a process is taken off the CPU at {time out}, then it is possible that 2 processes could enter the critical section at the same time void processOne(void) { while (1) while (p2inside) {stall} // time out p1inside = true; Critical Section p1inside = false; Other Stuff }

Software Solution 3   Comments: This method provides mutual exclusion The system could deadlock if at the point there //comment appears, process it taken off the processor and P2 then executes the same instruction. void processOne(void) { while (1) P1wantsToEnter = true; // comment while (P2wantsToEnter) {// stall} Critical Section P1wantToEnter = false; Other Stuff }

Dekker’s Algorithm Comments: Solves Critical Section problem   Comments: Solves Critical Section problem Has Busy waiting. favoredProcess is used to break a tie. void processOne(void) { while (1) P1wantsToEnter = true; while (P2wantsToEnter) if (favoredProcess == second) P1wantsToEnter = false; while (favoredProcess = second) {// stall} } Critical Section favoredProcess = second; P1wantToEnter = false; Otherstuff

Peterson’s Algorithm (1981)   Comments: Same as Dekkers’s but the process that executes: “favoredprocess = other” last will lose the tie breaker. void processOne(void) { while (1) P1wantsToEnter = true; favoredProcess = second; // comment while (P2wantsToEnter AND (favoredProcess == second)) {stall} Critical Section P1wantToEnter = false; Other Stuff }

Hardware TestAndSet instruction TESTANDSET is a hardware instruction (therefore atomic) that reads a variables current value while setting it to a new value all in 1 machine instruction. Read the value of X while setting X to 0 X is a variable with values of 0(not available) or 1(available) process() { a = 0; (while a == 0) { a = TESTANDSET(X) } Critical Section X = 1; }