Monitor Object Pattern

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science and Engineering Washington University in St. Louis.
Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
1/25 Concurrency and asynchronous computing How do we deal with evaluation when we have a bunch of processors involved?
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.
Synchronization in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS533 - Concepts of Operating Systems 1 CS533 Concepts of Operating Systems Class 8 Synchronization on Multiprocessors.
Fundamentals of Python: From First Programs Through Data Structures
CSE 425: Concurrency III Monitors A monitor is a higher level construct for synchronizing multiple threads’ access to a common code segment –Can implement.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Proactor Pattern Venkita Subramonian & Christopher Gill
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Concurrency Patterns Emery Berger and Mark Corner University.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Reusing threads.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Software Systems Advanced Synchronization Emery Berger and Mark Corner University.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Venkita Subramonian, Christopher Gill, Ying Huang, Marc Sentany Department of Computer Science.
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Chris Gill Department of Computer Science and Engineering Washington University in St. Louis.
1 G53SRP: Java Concurrency Control (2) – wait/notify Chris Greenhalgh School of Computer Science.
3/17/2016cse synchronization-p2 © Perkins, DW Johnson and University of Washington1 Synchronization Part 2 CSE 410, Spring 2008 Computer.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Pitfalls: Time Dependent Behaviors CS433 Spring 2001 Laxmikant Kale.
Kernel Synchronization David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
C++11 Atomic Types and Memory Model
Component Configurator
Introduction to Generic Programming in C++
CSCD 330 Network Programming
Introduction to Concurrency: Synchronization Mechanisms
Threaded Programming in Python
Event Handling Patterns Asynchronous Completion Token
C++11 Threading Lieven de Cock
EEC 688/788 Secure and Dependable Computing
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
Overview of the Lab 2 Assignment: Linux Scheduler Profiling
The Active Object Pattern
Condition Variables and Producer/Consumer
Multithreading.
Condition Variables and Producer/Consumer
Race Conditions & Synchronization
Producer-Consumer Problem
EEC 688/788 Secure and Dependable Computing
Half-Sync/Half-Async (HSHA) and Leader/Followers (LF) Patterns
Multithreading.
Concurrency in Java Last Updated: Fall 2010 Paul Ammann SWE 619.
Concurrency: Mutual Exclusion and Process Synchronization
Threaded Programming in Python
Testing and Debugging Concurrent Code
Kernel Synchronization I
EEC 688/788 Secure and Dependable Computing
Kernel Synchronization II
CSE 451 Section 1/27/2000.
“The Little Book on Semaphores” Allen B. Downey
Monitors and Inter-Process Communication
Software Engineering and Architecture
CSE 542: Operating Systems
CSE 542: Operating Systems
Synchronization and liveness
Presentation transcript:

Monitor Object Pattern E81 CSE 532S: Advanced Multi-Paradigm Software Development Concurrency Patterns and the Monitor Object Pattern Chris Gill, Venkita Subramonian, Olcan Sercinoglu, Thomas Shepherd, Jim Luo Department of Computer Science and Engineering Washington University, St. Louis cdgill@cse.wustl.edu Title slide

Concurrency Patterns Key issue: sharing resources across threads Thread Specific Storage Pattern Separates resource access to avoid contention among them Monitor Object Pattern One thread at a time can access the object’s resources Active Object Pattern One worker thread owns the object‘s resources Half-Sync/Half-Async (HSHA) Pattern A thread collects asynchronous requests and works on the requests synchronously (similar to Active Object) Leader/Followers Pattern Optimize HSHA for independent messages/threads

Design Forces Need to prevent race conditions but allow incremental progress of threads within the object Methods define (intuitive) synchronization boundaries But, may need to check state etc. before proceeding A refinement: only one method at a time is active within object Synchronization must be transparent to caller Client must not be concerned with synchronization The executing method must be able to give up control Other clients can access the object Allows “controlled” concurrency Object must be left “stable” during control transitions Race conditions: uncontrolled concurrent changes “Controlled” concurrency is one where internals are protected and deadlock is prevented Stable: object-specific invariants must hold

Desired Internal Behavior notify Queue empty - wait Queue

Solution: (Passive) Monitor Object Make object a “Monitor Object” Methods run in callers’ threads Condition variables arbitrate use of a common shared lock E.g., using a std::mutex, a std::unique_lock (must be able to unlock and re-lock it) and a std::condition_variable Ensures incremental progress while avoiding race conditions Thread waits on condition Condition variable performs thread-safe lock/sleep and unlock/release operations Thread released when it can proceed E.g., when queue isn’t empty/full Blocks caller until request can be handled, coordinates callers Client Proxy List (Monitor Object) add() Condition lookup() Transparent in the sense that the caller does not need to deal with external synchronization objects. Easy implementation is a big plus. Lock

A Few Variations Can notify_one() or notify_all() If it doesn’t matter which thread, just wake one up If all need to see if it’s their turn, wake all of them Can limit waiting time Use wait_for() to return after a specified interval Use wait_until() to return at a specified time Can pass a predicate to wait (or wait_*) method(s) Won’t return until predicate is satisfied (or call times out) Helps to avoid spurious wake cases