Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
02/27/2004CSCI 315 Operating Systems Design1 Process Synchronization Deadlock Notice: The slides for this lecture have been largely based on those accompanying.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
Dining-Philosophers Problem Shared data fork[5]: semaphore; initialized to 1.
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Process Synchronization
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
02/25/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
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.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
© 2004, D. J. Foreman 1 High Level Synchronization and Inter-Process Communication.
Operating Systems Review for Chap.6 & 7 Hung Q. Ngo KyungHee University Spring 2009
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.
Midterm 1 – Wednesday, June 4  Chapters 1-3: understand material as it relates to concepts covered  Chapter 4 - Processes: 4.1 Process Concept 4.2 Process.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Synchronizing Threads with Semaphores
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
Operating Systems Lecture Notes Synchronization Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
CS4315A. Berrached:CMS:UHD1 Process Synchronization Chapter 8.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Auburn University COMP 3500 Introduction to Operating Systems Project 3 – Synchronization Cats and Mice Dr. Xiao Qin.
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Process Synchronization: Semaphores
Chapter 5: Process Synchronization – Part 3
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
PARALLEL PROGRAM CHALLENGES
Background on the need for Synchronization
Chapter 5: Process Synchronization – Part II
Chapter 5: Process Synchronization
CSE451 Basic Synchronization Spring 2001
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization (Con’t)
CS 153 Design of Operating Systems Winter 2016
Semaphore Originally called P() and V() wait (S) { while S <= 0
Lecture 22 Syed Mansoor Sarwar
Module 7a: Classic Synchronization
Lecture 2 Part 2 Process Synchronization
Critical section problem
Unit 2: Chemistry Lesson 2: Classifying Matter Essential Questions: 1
Monitor Giving credit where it is due:
The Elements of the Periodic Table
Chapter 7: Synchronization Examples
Unit 2: Chemistry Lesson 2: Classifying Matter Essential Questions: 1
Balancing Equations In Chemical Reactions.
Problem: CFQ (Circular Fifo Queue)
FIRST SOLUTION Producer Process Consumer Process
Tuesday, October 29, 2013 Please clear your desk for you quiz.
Chemical reactions kathryn thumath 25/08/2019.
Synchronization and liveness
Presentation transcript:

                                                                                                                                                                                                             H2O

A chemical reaction is the pathway by which two substances bond together. Chemical reactions happen all around us: when we light a match, start a car, eat dinner or walk the dog. 

One reaction we are mentioning today is the reaction of hydrogen with oxygen to form water.

Problem Statement So lets Consider the problem of making water. One oxygen atom and two hydrogen atoms are needed to be combined to make water.

Synchronization Now lets assume that atoms are processes, and that exactly two hydrogen and one oxygen process must call the procedure makeWater at once to create water.

Semaphores We used semaphores to provide a solution to this problem because semaphores is considered a common and efficient tool for synchronization. A semaphore is an object with 2 methods: 1) Wait:  The counter of the process is positive: counter decreased by 1, thread resumes execution.  The counter of the process is zero: thread is suspended and placed in a private queue.

2) Signal:  The queue of the process has no waiting thread: counter increased by one.  The queue of the process has waiting threads: counter must be 0.

Hydrogen Process: while (1) { wait(hydrogen); wait(mutex); waiting++; if (waiting == 3) then signal(go); signal(go); signal(go); else signal(mutex); wait(go); // makeWater(); signal(hydrogen); }

Oxygen Process { wait(oxygen); wait(mutex); waiting++; while (1) { wait(oxygen); wait(mutex); waiting++; if (waiting == 3) then signal(go); signal(go); signal(go); else signal(mutex); wait(go); // makeWater(); signal(oxygen); }

Deadlock In this program, things will quickly come to a halt as all processes start up and immediately start waiting on one of the two counters, which all start as zero. Every process is then waiting for an action to be taken by another process, and we will have a deadlock and starvation situation.

Solution We can eliminate this problem by changing the order for one of the elements. One of the processes has to make the first move. If hydrogen first signals hydrogen available and then waits on the oxygen counter, it will break the deadlock because raising the hydrogen count allows the oxygen process to get through acquiring hydrogen to signal the oxygen needed by the hydrogen process, which will allow both the elements to move on.

Solution continued… Initial Values semaphore mutex = 1 semaphore hydrogen = 2 semaphore oxygen = 1 semaphore go = 0 variable int waiting = 0

Hydrogen Process: while (1) { wait(hydrogen);  initial value =2  value = 2-1= 1 wait(mutex);  initial value = 1  value = 1-1 = 0 //One Hydrogen Atom waiting++;  value = 1 if (waiting == 3) then signal(go); signal(go); signal(go); else signal(mutex);  value of mutex = 0

Oxygen Process: while (1) { wait(oxygen);  initial value = 1 wait(mutex); // One Oxygen atom waiting++;  value = 2 if (waiting == 3) then signal(go); signal(go); signal(go); else signal(mutex);  value = 0

Hydrogen Process: while (1) { wait(hydrogen);  previous value = 1  new value = 1-1 = 0 wait(mutex); // 2 Hydrogen Atom waiting++;  value = 3 if (waiting == 3) then // enters loop signal(go); signal(go); signal(go); else signal(mutex); go++; wait(go); // makeWater(); // H2O ready signal(hydrogen); }

Conclusion Semaphores is the best synchronization tool which is an efficient way to solve problems and provide a deadlock free algorithm.