Chapter 6 – Concurrent Programming Outline 6.1 Introduction 6.2Monitors 6.2.1Condition Variables 6.2.2Simple Resource Allocation with Monitors 6.2.3Monitor.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Synchronization with Eventcounts and Sequencers
Operating Systems Part III: Process Management (Process Synchronization)
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Ch 7 B.
CSCC69: Operating Systems
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
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.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Monitors Chapter 7. The semaphore is a low-level primitive because it is unstructured. If we were to build a large system using semaphores alone, the.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
1 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 L49 Multithreading (1). 2 OBJECTIVES  What threads are and why they are useful.  How threads enable you to manage concurrent activities.  The life.
Chapter 5 Concurrency: Mutual Exclusion and 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.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Monitors CSCI 444/544 Operating Systems Fall 2008.
1 Chapter 6: Concurrency: Mutual Exclusion and Synchronization Operating System Spring 2007 Chapter 6 of textbook.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
CS Introduction to Operating Systems
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings 1.
Concurrency, Mutual Exclusion and Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 2 Processes and Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
OPERATING SYSTEMS Frans Sanen.  Recap of threads in Java  Learn to think about synchronization problems in Java  Solve synchronization problems in.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Synchronizing Threads with Semaphores
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
Lecture 6: Monitors & Semaphores. Monitor Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-2: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Homework-6 Questions : 2,10,15,22.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Background on the need for Synchronization
Chapter 5: Process Synchronization
CS510 Operating System Foundations
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Concurrency: Mutual Exclusion and Synchronization
Midterm review: closed book multiple choice chapters 1 to 9
Concurrency: Mutual Exclusion and Process Synchronization
Monitor Giving credit where it is due:
CSE 153 Design of Operating Systems Winter 2019
Chapter 6: Synchronization Tools
CSE 542: Operating Systems
CSE 542: Operating Systems
Review The Critical Section problem Peterson’s Algorithm
Presentation transcript:

Chapter 6 – Concurrent Programming Outline 6.1 Introduction 6.2Monitors 6.2.1Condition Variables 6.2.2Simple Resource Allocation with Monitors 6.2.3Monitor Example: Circular Buffer 6.2.4Monitor Example: Readers and Writers 6.3Java Monitors 6.4Java Multithreading Case Study, Part III: Producer/Consumer Relationship in Java 6.5Java Multithreading Case Study, Part IV: Circular Buffer in Java

Objectives After reading this chapter, you should understand: –how monitors synchronize access to data. –how condition variables are used with monitors. –solutions for classic problems in concurrent programming such as readers and writers and circular buffer. –Java monitors. –remote procedure calls.

6.2.1 Introduction Recent interest in concurrent programming languages –Naturally express solutions to inherently parallel problems –Due to proliferation of multiprocessing systems, distributed systems and massively parallel architectures –More complex than standard programs More time required to write, test and debug

6.2 Monitors Monitor –Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for threads outside monitor to access monitor data

6.2 Monitors Resource allocation using monitors –T hread must call monitor entry routine –Mutual exclusion is rigidly enforced at monitor boundary –A thread that tries to enter monitor when it is in use must wait

6.2 Monitors Threads return resources through monitors as well –Monitor entry routine calls signal Alerts one waiting thread to acquire resource and enter monitor –Higher priority given to waiting threads than ones newly arrived Avoids indefinite postponement

6.2.1 Condition Variables Before a thread can reenter the monitor, the thread calling signal must first exit monitor –Signal-and-exit monitor Requires thread to exit the monitor immediately upon signaling Signal-and-continue monitor –Allows thread inside monitor to signal that the monitor will soon become available –Still maintain lock on the monitor until thread exits monitor –Thread can exit monitor by waiting on a condition variable or by completing execution of code protected by monitor

6.2.4 Monitor Example: Readers and Writers Readers –Read data, but do not change contents of data –Multiple readers can access the shared data at once –When a new reader calls a monitor entry routine, it is allowed to proceed as long as no thread is writing and no writer thread is waiting to write –After the reader finishes reading, it calls a monitor entry routine to signal the next waiting reader to proceed, causing a “chain reaction” Writers –Can modify data –Must have exclusive access

Figure 6.3 Monitor pseudocode for solving the readers and writers problem. (Part 1 of 3.) Monitor Example: Readers and Writers

Figure 6.3 Monitor pseudocode for solving the readers and writers problem. (Part 2 of 3.) Monitor Example: Readers and Writers

Figure 6.3 Monitor pseudocode for solving the readers and writers problem. (Part 3 of 3.) Monitor Example: Readers and Writers

Group Discussion 6, 2/26/09 1. Indicate what X is in each of the following, a semaphore or a conditional variable. (a). each X is Associated with a queue (b). wait(X) does not always block the caller; (c). wait(X) always blocks the caller; (d). signal(X) releases a blocked thread if there is any, or does nothing; (e). signal(X) either releases a blocked thread or increments the value of X; (f). X is a local variable; (g). X is a global variable; (h). Programs using X is prone to bugs;

Group Discussion 6 2. Suppose that at some moment of time, the following threads made the following calls T1.beginRead(); T2.beginRead(); T3.beginWrite(); T4.beginWrite(); (a). Assume T1 gets in the monitor first. Draw a diagram of the monitor and the waiting queues. (b). Assume T1 finished reading after the queues in the above questions have formed, which thread is the next one gets in the monitor? Draw a diagram of the monitor and queues. (c). Who will be the next thread gets in the monitor?