Concurrency Design Patterns

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

How to Build Multi- threaded Applications in.NET Mazen S. Alzogbi Technology Specialist Microsoft Corporation.
Chapter 7 - Resource Access Protocols (Critical Sections) Protocols: No Preemptions During Critical Sections Once a job enters a critical section, it cannot.
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 8 SCHEDULING.
A Sample RTOS Presentation 4 Group A4: Sean Hudson, Manasi Kapadia Syeda Taib.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: 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.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Model for Supporting High Integrity and Fault Tolerance Brian Dobbing, Aonix Europe Ltd Chief Technical Consultant.
Big Picture Lab 4 Operating Systems Csaba Andras Moritz.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Process Description and Control
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Concurrency in Ada What concurrency is all about Relation to operating systems Language facilities vs library packages POSIX threads Ada concurrency Real.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Chapter 11: Distributed Processing Parallel programming Principles of parallel programming languages Concurrent execution –Programming constructs –Guarded.
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
User-Level Interprocess Communication for Shared Memory Multiprocessors Brian N. Bershad, Thomas E. Anderson, Edward D. Lazowska, and Henry M. Levy Presented.
Chapter 8 Windows Outline Programming Windows 2000 System structure Processes and threads in Windows 2000 Memory management The Windows 2000 file.
(C) 2009 J. M. Garrido1 Object Oriented Simulation with Java.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 101 Multiprocessor and Real- Time Scheduling Chapter 10.
111 © 2002, Cisco Systems, Inc. All rights reserved.
1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.
1 Concurrency Architecture Types Tasks Synchronization –Semaphores –Monitors –Message Passing Concurrency in Ada Java Threads.
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.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.
Real Time Operating Systems Michael Thomas Date: Rev. 1.00Date.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Venkita Subramonian, Christopher Gill, Ying Huang, Marc Sentany Department of Computer Science.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
CS333 Intro to Operating Systems Jonathan Walpole.
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Big Picture Lab 4 Operating Systems C Andras Moritz
Outlines  Introduction  Kernel Structure  Porting.
REAL-TIME OPERATING SYSTEMS
Threaded Programming in Python
Threads vs. Events SEDA – An Event Model 5204 – Operating Systems.
Operating Systems (CS 340 D)
Outline Other synchronization primitives
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Other Important Synchronization Primitives
Real-time Software Design
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Concurrency: Mutual Exclusion and Synchronization
Process Description and Control
Monitor Object Pattern
Process Description and Control
Process Description and Control
Operating Systems : Overview
Process Description and Control
Operating Systems : Overview
Operating Systems : Overview
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 19
Chapter 3: Process Management
Presentation transcript:

Concurrency Design Patterns By: Kalpana Nallavolu Nestor Rivera Feras Batarseh

Design Patterns A design pattern is a formal way of documenting successful solutions to problems. Reusability, modularity, win time. Resign Pattern Ex: fatal, misbehavior.

Contributors Christopher Alexander GoF

Concurrency Design Patterns Concurrency Pattern Message Queuing Pattern Interrupt Pattern Guarded Call Pattern Rendezvous Pattern Cyclic Executive Pattern Round Robin Pattern Static Priority Pattern Dynamic Priority Pattern

Background Thread Concurrency Concurrency Architecture Active Object Passive objects

Collaboration Of Objects

Collaboration Of Objects 2 The active object accept messages and delegate them to the internally contained application objects for processing. The issues around the concurrency management are varied depending 1) The threads are completely independent 2) The threads are not really independent.

Message Queuing Pattern

Message Queuing Pattern It provides a simples means of communication among threads. It uses asynchronous communication. Information shared among threads is passed by value to the separate thread. Advantages and disadvantages

Pattern Structure

Sample Model

Interrupt Pattern

Interrupt Pattern In many real-time applications, certain events must be responded quickly and efficiently regardless of what system is doing. This method is rarely used as only concurrency strategy Advantages and disadvantages.

Pattern Structure

Sample Model

Guarded Call Pattern

Guarded Call Pattern – Abstract Problem with Message Queuing Pattern…? Asynchronous & slow What if urgency? Alternative -> synchronously invoke a method of an object Data integrity is key -> mutual exclusion Need to avoid ->synchronization & deadlock problems

Guarded Call Pattern – Collaboration Roles I Server Thread: <<active object>> Server Object Shared Resource Protection with Mutex Client Thread: <<active object>> Client object Synchronously invoke method

Guarded Call Pattern – Collaboration Roles II Boundary Object Protected interface to server objects with operations Mutex Mutual exclusion semaphore object Permits only single caller through time Safer if invoked by relevant operations Locks and unlocks shared resource Blocks client threads

Guarded Call Pattern – Collaboration Roles III Server Uses the shared resource object Provides the service to client across the thread boundary Shared Resource Provides data or service Shared by multiple servers Integrity must be protected => serialization of access

Guarded Call Pattern - Consequences Timely response (unless services are locked) Simplification: no interaction among servers => boundary object, contain shared resource & one mutex/server

Guarded Call Pattern – Related Patterns Message Queuing, Interrupt, Guarded Call & Rendezvous could be mixed Race conditions may appear If server is stateful, monitor on server may be needed

Guarded Call Pattern – Class Diagram

Guarded Call Pattern Example - Structure

Guarded Call Pattern Example - Scenario

Rendezvous Pattern

Rendezvous Pattern Simplified form of Guarded Call Pattern (synchronize threads) Rendezvous Object => means for synchronization (synchronization point, policy or precondition)

Rendezvous Pattern - Abstract Precondition => specified to be true prior to an action/activity Behavioral model => each thread registers with Rendezvous class and blocks until released

Rendezvous Pattern – Collaboration Roles I Callback: holds address of client thread Client Thread At synchronization points, register Pass their callbacks i.e. notify() called once condition met

Rendezvous Pattern – Collaboration Roles II Manages thread synchronization Has register() operation Sync Policy Reifies set of preconditions into single concept i.e. Registration count (Thread Barrier Pattern)

Rendezvous Pattern – Class Diagram

Rendezvous Pattern – Sync Policy State Chart

Rendezvous Pattern Example - Structure

Rendezvous Pattern Example - Scenario

Cyclic Executive Pattern

Cyclic Executive Pattern Very small systems (execution predictability is crucial) Easy to implement Can run in memory constraint systems (no RTOS) Executes tasks in turn, from first to last and starts over again (cycle)

Cyclic Executive Pattern – Collaboration Roles Abstract Thread Super class for concrete thread Interface to the scheduler Concrete Thread <<active object>> Contains passive objects Scheduler Initializes system (loads tasks) Runs each of them in turn in perpetuity

Cyclic Executive Pattern – Properties of Applications Constant number of tasks Amount of task time is unimportant or consistent Tasks are independent Usage of shared resources complete after each task Sequential ordering of tasks is adequate

Cyclic Executive Pattern – Pros and Cons Primary advantage => simplicity Primary Disadvantages Lack of flexibility Non-optimality Instability to violation of its assumptions Response to incoming event: deadline >= cycle time No criticality or urgency: all threads are equally important.

Cyclic Executive Pattern – Class Diagram

Cyclic Executive Pattern Example - Structure

Cyclic Executive Pattern Example - Scenario

Round Robin Pattern

Introduction Hardcore real time deadline! A “fairness” scheduling method. All tasks progress than specific deadline to be met. Entire set movement.

The Model Abstract thread: super class, associates with scheduler. Concrete thread: (active thread) real work of the system. Scheduler: initialize the tasks and run them. Stack: control and data; variables, return variables Task control block Timer: ticks for scheduler, front end to the hardware timer, switch task();

Pros and Cons All tasks get the chance to run. Misbehaving task wont ruin the system. Scale up better to big systems. Higher switching time… All tasks take the same time slice! Priority?

Related Patterns More complex than cyclic executive Less complex than priority patterns, discussed next. Special kind that gives each task its time.

Static Priority Pattern

Introduction Priorities predefined. Common approach, simple, large number of tasks. Urgency (time) + Criticality (importance)

The Model Abstract thread Blocked queue: queue for TCB, blocked tasks in, out to ready queue. Concrete thread Shared resources Mutex: semaphore object that allows one caller object (thread) to access shared resources. Mutex ID, entry point.

The Model 2 Ready queue: reference to tasks ready to execute next. even running tasks could be interrupted by looking at the RQ. Scheduler: calls start address of higher and ready thread. Stack: parameters for threads. Task control block: priority and entry address

Pros and Cons Simplicity Stability Changing conditions, reallocation? (DPP) Low priority tasks?

Dynamic Priority Pattern

Introduction Automatically update of tasks priorities. Urgency over criticality, thus Earliest deadline first. Sets priority as time remaining function.

The Model Abstract thread Blocked queue: queue for TCB, blocked tasks in, out to ready queue. Concrete thread Ready queue: reference to tasks ready to execute next, closest to deadline on top. even running tasks could be interrupted by looking at the RQ.

The Model 2 Scheduler: computes the priority dynamically due to closest deadline. Stack: return addresses and parameters for threads. Task control block: priority and entry address after scheduler computations. Shared resources Mutex: semaphore object that allows one caller object (thread) to access shared resources.

Pros and Cons Flexible Optimal Scales well to large systems Not stable Complex

Related Patterns Not as common as SPP More complex than other patterns

References [book] Real time design patterns: Patterns: robust scalable architecture for real-time systems [book] Design patterns: Elements of reusable object-oriented software Gomma, Hassan Software Design Methods for concurrent and real timeSystems, Reading , Addison-Wesley 1993 IEEE Papers Database wikipedia.com...and a couple of other websites

Thank you for your attention. Questions?