Design Patterns in Operating Systems

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Design Patterns Pepper. Find Patterns Gang of Four created 23 Siemens published another good set x
Jan Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Oct Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Nov R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (section 23.3 has a Simple.
March R McFadyen1 Design Patterns (GoF) contains the creational patterns: Abstract factory Builder Factory method (in Larman) Prototype Singleton.
Design Patterns CS is not simply about programming
March R McFadyen1 GoF (Gang of Four): Gamma, Johnson, Helm & Vlissides Book: Design Patterns: Elements of Reusable Object-Oriented Software.
Spring 2010ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Fall 2009ACS-3913 R McFadyen1 Singleton Problem: Exactly one instance of a certain object is required (this object is called a singleton). We must ensure.
1 Scenario: Audio Clip Imagine that your application played an audio clip Based on user action, a different audio clip may begin playing You want only.
March Ron McFadyen1 Singleton pattern Singleton is designed to restrict instantiation of a class to one (or a few) objects. Useful when exactly.
Factory Design Pattern, cont’d COMP 401 Fall 2014 Lecture 13 10/2/2014.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Winter 2007ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Design Patterns.
Implementing Design Patterns Using Java St. Louis Java Special Interest Group Eric M. Burke Object Computing, Inc. Presented on July 9, 1998 (updated July.
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Singleton and Basic UML CS340100, NTHU Yoshi. What is UML Unified Modeling Language A standardized general-purpose modeling language in the field of software.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Design Patterns Singleton & Factory Pattern Eriq Muhammad Adams J. Mail : | Blog :
1 More OO Design Patterns CSC 335: Object-Oriented Programming and Design.
July 28, 2015IAT 2651 Design Patterns. “Gang of Four” July 28, 2015IAT 2652.
CSC 480 Software Engineering Design With Patterns.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns David Talby. This Lecture Re-routing method calls Chain of Responsibility Coding partial algorithms Template Method The Singleton Pattern.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
Patterns in programming
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Chapter 4: Threads.
Factory Method Pattern
Chapter 10 Design Patterns.
Presentation on GoF Design Patterns Submitted by WWW. ASSIGNMENTPOINT
MPCS – Advanced java Programming
Design Patterns – Chocolate Factory (from Head First Design Patterns)
Introduction to Design Patterns
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Singleton Pattern Command Pattern
Factory Method Pattern
Design Patterns (GoF) contains the creational patterns:
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
object oriented Principles of software design
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
Advanced Programming Behnam Hatami Fall 2017.
Software Engineering Lecture 7 - Design Patterns
GoF Design Patterns (Ch. 26)
Object Oriented Design Patterns - Creational Patterns
CSC 480 Software Engineering
Advanced ProgramMING Practices
Advanced ProgramMING Practices
CS 325: Software Engineering
CSC 480 Software Engineering
Designing For Testability
GoF Patterns Ch. 26.
Presentation transcript:

Design Patterns in Operating Systems

A Word on Patterns These routinely appear as solutions to common classes of problems They can help in numerous ways Well known resuable solution with documentation Pitfalls known in advance Performance and testing known & done in advance Generally offer levels of abstraction to cope with complexity by decoupling events and actions

Patterns in Operating Systems There are many, and we’ll examine a few closely The Observer, The Decorator, The Active Object, The Façade, The Singleton, The Visitor, The Factory

Singletons Used to share access to a singular object Usually, it’s an error to create this object twice Examples: A teller’s transaction log, a kernel’s memory manager thread, rollbacks Can be used (somewhat sloppily) to provide global access to a shared resource What kinds of issues arise in a SMP environment? For more information, see problem 6.21 in the text

UML Singleton ------------------------------------------ Data: (1) private object instance Methods: private Singleton() public getInstance()

The Action in a Singleton public Object getInstance() { if(myInstance == null) { //lazy instantiation myInstance = new Object(); } return myInstance;

Singletons and SMP Architectures Race Condition public Object getInstance() { if(myInstance == null) { myInstance = new Object(); } return myInstance;

Double-Checked Lock Somewhat similar in spirit to Petersons, but more general Check for null Acquire my lock Check again for null, and if null instantiate

DC Action in Java public Object getInstance() { if(myInstance == null) { mutex.acquire(); If(myInstance == null) { myInstance = new Object(); } mutex.release(); return myInstance;

DC Action in Java public Object getInstance() { if(myInstance == null) { mutex.acquire(); If(myInstance == null) { myInstance = new Object(); } mutex.release(); return myInstance; Two parallel threads may both discover myInstance to be null But only one will acquire the lock So the thread in first will build the (1) object The second thread blocks here and when released, notices myInstance is no longer null

Rewrite using synchronized blocks public Object getInstance() { if(myInstance == null) { mutex.acquire(); If(myInstance == null) { myInstance = new Object(); } mutex.release(); return myInstance;

Rewrite using synchronized blocks public synchronized Object getInstance() { //if(myInstance == null) { //no need now for this //mutex.acquire(); If(myInstance == null) { myInstance = new Object(); } //mutex.release(); return myInstance;

Double-Checked Locking More information on our message board and at: http://www.cs.wustl.edu/~schmidt/PDF/DC-Locking.pdf

Spinlocks Versus Blocking TestAndSet usually is a spinlock Semaphores frequently are implemented as blocking When is one more appropriate? Which is heavyweight? Would we ever not want to spin?

Socket Programming -> Too Low Level? What’s the solution? Make a class that wraps the low level details and provides a clean-and-simple interface You’ve just made a Façade or Wrapper Class

Façade or Wrapper Pattern Wrap an OO interface around existing code Or cross-platform library code Goals: Ease of use, simplicity, known pitfalls Example: rendering in Vista is done using DirectX, but those wanting to create windows & GUIs can still use createWindowEx()

GUI’s Further: The Decorator Defn: Allows users to wrap objects in containers that provide additional functionality. Example: new JScrollPane( new JTextArea()) new JBorder( new JTextArea())

The Decorator Pattern Observed

The Observer (from Wiki) “The observer pattern (a subset of the asynchronous publish/subscribe pattern) is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.”

More on Observer See java.util.Observer //listeners And java.util.Observable //the trigger Lets see some code… http://en.wikipedia.org/wiki/Observer_pattern

The Infamous Factory Defers Object instantiation to concrete subclasses Usually defined as an interface Lets make one for Windows

The Factory Pattern Observed public interface Factory { public Object create(); }