Concurency and synchronisation patterns based on Pattern-Oriented Software Architecture, Patterns for Concurrent and Networked Objects, Volume 2 by Douglas.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Broker Pattern Pattern-Oriented Software Architecture (POSA 1)
Lock-free Cache-friendly Software Queue for Decoupled Software Pipelining Student: Chen Wen-Ren Advisor: Wuu Yang 學生 : 陳韋任 指導教授 : 楊武 Abstract Multicore.
ECE 526 – Network Processing Systems Design Software-based Protocol Processing Chapter 7: D. E. Comer.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.
490dp Synchronous vs. Asynchronous Invocation Robert Grimm.
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
Seyed Mohammad Ghaffarian ( ) Computer Engineering Department Amirkabir University of Technology Fall 2010.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
Active Messages: a Mechanism for Integrated Communication and Computation von Eicken et. al. Brian Kazian CS258 Spring 2008.
Monitors CSCI 444/544 Operating Systems Fall 2008.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Threads© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Software Patterns - F04 Asynchronous Completion Token 1.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
SEDA: An Architecture for Well-Conditioned, Scalable Internet Services
Multithreading.
Week 9 Building blocks.
C. FlanaganType Systems for Multithreaded Software1 Cormac Flanagan UC Santa Cruz Stephen N. Freund Williams College Shaz Qadeer Microsoft Research.
9/8/2015cse synchronization-p1 © Perkins DW Johnson and University of Washington1 Synchronization Part 1 CSE 410, Spring 2008 Computer Systems.
Parallel Programming Models Jihad El-Sana These slides are based on the book: Introduction to Parallel Computing, Blaise Barney, Lawrence Livermore National.
Distributed Systems. Interprocess Communication (IPC) Processes are either independent or cooperating – Threads provide a gray area – Cooperating processes.
Pattern Oriented Software Architecture for Networked Objects Based on the book By Douglas Schmidt Michael Stal Hans Roehnert Frank Buschmann.
The HDF Group Multi-threading in HDF5: Paths Forward Current implementation - Future directions May 30-31, 2012HDF5 Workshop at PSI 1.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Architectural Styles.
E81 CSE 532S: Advanced Multi-Paradigm Software Development Venkita Subramonian, Christopher Gill, Guandong Wang, Zhenning Hu, Zhenghui Xie Department of.
Professor of EECS Vanderbilt University Nashville, Tennessee
Proactor Pattern Venkita Subramonian & Christopher Gill
Cohesion and Coupling CS 4311
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Explore Patterns in Context-Aware Applications --Using Reactor Pattern to Develop In/Out Board Fall 2002 Yu Du.
Internet Software Development Controlling Threads Paul J Krause.
© Siemens AG, CT SE, Prashant Jain, October 15, 2001 C O R P O R A T E T E C H N O L O G Y OOPSLA 2001 Workshop Software & Engineering Architecture 1 A.
Pattern-Oriented Software Architectures Patterns & Frameworks for Concurrent & Distributed Systems Dr. Douglas C. Schmidt
Pipes & Filters Architecture Pattern Source: Pattern-Oriented Software Architecture, Vol. 1, Buschmann, et al.
Concurrency Design Patterns
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Architectural pattern: Reactor Source: POSA II pp 179 – 214POSA II Environment: an application that receives multiple requests simultaneously but may process.
CS510 Concurrent Systems Why the Grass May Not Be Greener on the Other Side: A Comparison of Locking and Transactional Memory.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
Concurrency case studies in UNIX John Chapin October 26, 1998.
COSC 3407: Operating Systems Lecture 9: Readers-Writers and Language Support for Synchronization.
CS533 - Concepts of Operating Systems 1 Threads, Events, and Reactive Objects - Alan West.
3/17/2016cse synchronization-p2 © Perkins, DW Johnson and University of Washington1 Synchronization Part 2 CSE 410, Spring 2008 Computer.
Software Design 13.1 From controller to threads l Threads are lightweight processes (what’s a process?)  Threads are part of a single program, share state.
Threads, SMP and Microkernels Process vs. thread: –Unit of resource ownership (process has virtual address space, memory, I/O channels, files) –Unit of.
Pertemuan 09 Architectural Patterns Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
Distributed and Parallel Processing George Wells.
Jim Fawcett CSE 691 – Software Modeling and Analysis Fall 2000
Chapter 4: Threads.
CSE 120 Principles of Operating
Event Handling Patterns Asynchronous Completion Token
Design Components are Code Components
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Multithreaded Programming in Java
Threading And Parallel Programming Constructs
Half-Sync/Half-Async (HSHA) and Leader/Followers (LF) Patterns
Thread Implementation Issues
Operating Systems : Overview
Design Components are Code Components
Operating Systems : Overview
Operating Systems : Overview
Operating Systems : Overview
CSE 153 Design of Operating Systems Winter 19
Threads and Multithreading
Synchronization These notes introduce:
Presentation transcript:

Concurency and synchronisation patterns based on Pattern-Oriented Software Architecture, Patterns for Concurrent and Networked Objects, Volume 2 by Douglas Schmidt, Michael Stal, Hans Rohnert and Frank Buschmann

Design Pattern A design pattern is a general reusable solution to a commonly occurring problem in software design.

Agenda Synchronisation patterns – Scoped Locking – Strategized Locking – Thread-Safe Interface Concurency patterns – Active Object – Leader/Followers

Scoped Locking The Scoped Locking C++ idiom ensures that a lock is acquired when control enters a scope and released automatically when control leaves the scope, regardless of the return path from the scope.

Scoped Locking - Implementation class Thread_Mutex_Guard { public: Thread_Mutex_Guard (Thread_Mutex &lock) : lock_ (&lock), owner_ (false) { lock_->acquire (); owner_ = true; } ~Thread_Mutex_Guard () { if (owner_) lock_->release (); } private: Thread_Mutex *lock_; bool owner_; Thread_Mutex_Guard (const Thread_Mutex_Guard&); void operator= (const Thread_Mutex_Guard &); };

Scoped Locking – Explicit Accessors class Thread_Mutex_Guard { public: Thread_Mutex_Guard (Thread_Mutex &lock) : lock_ (&lock), owner_ (false) { acquire (); } ~Thread_Mutex_Guard () { release (); } void acquire () { lock_->acquire (); owner_ = true; } void release () { if (owner_) { owner_ = false; lock_->release (); } private: Thread_Mutex *lock_; bool owner_; };

Scoped Locking – Example class Test { public: void test_function_1 { Thread_Mutex_Guard quard(&lock_); //do something } void test_function_2 { Thread_Mutex_Guard quard(&lock_); //do something } private: Thread_Mutex lock_; };

Scoped Locking - Consequences Benefits – Increased robustness Liabilities – Potential for deadlock when used recursively. – Limitations with language-specific semantics. Thread_Mutex_Guard guard (&lock_); Table_Entry *entry = lookup_or_create (path); if (entry == 0) pthread_cancel(pthread_self()); – Excessive compiler warnings

Strategized Locking Similar to Scoped Locking but pass template or polymorphic lock object to the guard constructor. class Lock { public: virtual void acquire () = 0; virtual void release () = 0; };

Strategized Locking - Example class Lock { public: virtual void acquire () = 0; virtual void release () = 0; }; class Thread_Mutex_Lock : public Lock { public: virtual void acquire () { lock_.acquire (); } virtual void release () { lock_.release (); } private: Thread_Mutex lock_; };

Scoped Locking – Example class Test { public: void test_function_1 { Thread_Mutex_Guard quard(&lock_); //do something } void test_function_2 { Thread_Mutex_Guard quard(&lock_); //do something } private: Thread_Mutex lock_; };

Strategized Locking - Example template class quard_t { private: boollocked; T& protector; guard_t(const guard_t& orig); public: guard_t(T& _protector) : protector(_protector), locked(false) { protector.acquire(); } virtual ~guard_t() { if (locked) protector.release(); } void release() { if (locke) { protector.release(); locked = false;} }; void acquire() {protector.acquire(); locked = true;}; };

Scoped Locking – Example class Test { public: void test_function_1 { quard quard(&lock_); //do something } void test_function_2 { quard quard(&lock_); //do something } private: Thread_Mutex lock_; };

Strategized Locking - Example typedef File_Cache Content_Cache;

Strategized Locking - Consequences Benefits – Enhanced flexibility and customization. – Decreased maintenance effort for components. – Improved reuse. Liabilities – Obtrusive locking. – Over-engineering.

Thread-Safe Interface The Thread-Safe Interface design pattern minimizes locking overhead and ensures that intra-component method calls do not incur 'self- deadlock' by trying to reacquire a lock that is held by the component already.

Thread-Safe Interface Example template class File_Cache { public: const void *lookup (const string &path) const { Guard guard (lock_); return lookup_i (path); } void insert (const string &path) { Guard guard (lock_); insert_i (path); } private: mutable LOCK lock_; const void *lookup_i (const string &path) const { const void *file_pointer = check_cache_i(path); if (file_pointer == 0) { insert_i (path); file_pointer = check_cache_i (path); } return file_pointer; } const void *check_cache_i (const string &) const {} void insert_i (const string &) {}

Consequences Benefits – Increased robustness. – Enhanced performance. – Simplification of software. Liabilities – Additional indirection and extra methods. – Potential deadlock. – Potential for misuse. – Potential overhead.

Active Object The Active Object design pattern decouples method execution from method invocation to enhance concurrency and simplify synchronized access to objects that reside in their own threads of control.

Active Object Methods invoked on an object concurrently should not block the entire process, Synchronized access to shared objects should be simple, Applications should be designed to transparently leverage the parallelism available on a hardware/software platform

Active Object

Consequences Benefits – Enhance application concurrency and simplify synchronization complexity, – Transparently leverage available parallelism, – Method execution order can differ from method invocation order Liabilities – Performance overhead. – Complicated debugging.

Leader/Followers The Leader/Followers design pattern provides a concurrency model where multiple threads can efficiently demultiplex events and dispatch event handlers that process I/O handles shared by the threads.

Leader/Followers Efficient demultiplexing of I/O handles and threads, Minimize concurrency- related overhead, Prevent race conditions

Leader/Followers

Consequences Benefits – Performance enhancements. It enhances CPU cache affinity and eliminates unbound allocation and data buffer sharing between threads, It minimizes locking overhead by not exchanging data between threads, It can minimize priority inversion because no extra queuing is introduced in the server, It does not require a context switch to handle each event – Programming simplicity. Liabilities – Implementation complexity. – Lack of flexibility. – Network I/O bottlenecks.