CS636: Shared Memory Synchronization Swarnendu Biswas

Total Page:16

File Type:pdf, Size:1020Kb

CS636: Shared Memory Synchronization Swarnendu Biswas CS636: Shared Memory Synchronization Swarnendu Biswas Semester 2018-2019-II CSE, IIT Kanpur Content influenced by many excellent references, see References slide for acknowledgements. What is the desired property? class Set { final Vector elems = new Vector(); void add(Object x) { if (!elems.contains(x)) { elems.add(x); } } } class Vector { synchronized void add(Object o) { ... } synchronized boolean contains(Object o) { ... } } CS636 Swarnendu Biswas 2 What is the desired property? Q.insert(elem): Q.remove(): atomic { atomic { while (Q.full()) {} while (Q.empty()) {} // Add elem to the Q // Return data from Q } } CS636 Swarnendu Biswas 3 Implementing Synchronization Patterns • Condition synchronization while ¬ condition // do nothing (spin) • Mutual exclusion lock:bool := false Lock.acquire(): Lock.release(): while TAS(&lock) lock := false // spin CS636 Swarnendu Biswas 4 Locks (Mutual Exclusion) public interface Lock { Lock mtx = new LockImpl(…); public void lock(); … public void unlock(); mtx.lock(); } try { … // body public class LockImpl } finally { implements Lock { mtx.unlock(); … } … } CS636 Swarnendu Biswas 5 Desired Synchronization Properties • Mutual exclusion or safety Critical sections on the same lock from different threads do not overlap • Livelock freedom If a lock is available, then some thread should be able to acquire it within bounded steps. CS636 Swarnendu Biswas 6 Desired Synchronization Properties • Deadlock freedom If some thread attempts to acquire the lock, then some thread should be able to acquire the lock • Starvation freedom • Every thread that acquires a lock eventually releases it • A lock acquire request must eventually succeed within bounded steps CS636 Swarnendu Biswas 7 Classic Mutual Exclusion Algorithms CS636 Swarnendu Biswas 8 Peterson’s Algorithm class PetersonLock { public void lock() { int i = ThreadID.get(); static volatile boolean[] flag = int j = 1-i; new boolean[2]; flag[i] = true; static volatile int victim; victim = i; while (flag[j] && victim == i) {} public void unlock() { } int i = ThreadID.get(); flag[i] = false; } } CS636 Swarnendu Biswas 9 Peterson’s Algorithm class PetersonLock { public void lock() { int i = ThreadID.get(); static volatile boolean[] flag = int j = 1-i; new boolean[2]; flag[i] = true; static volatile intIs thisvictim; algorithm correctvictim under = i ; sequential consistency?while (flag[j] && victim == i) {} public void unlock() { } int i = ThreadID.get(); flag[i] = false; } } CS636 Swarnendu Biswas 10 What could go wrong? class TwoThreadLockFlags { public void unlock() { int i = ThreadID.get(); static volatile boolean[] flag = new flag[i] = false; boolean[2]; } public void lock() { } int i = ThreadID.get(); flag[i] = true; while (flag[j]) {} // wait } CS636 Swarnendu Biswas 11 What could go wrong? class TwoThreadLockVolatile { public void unlock() { } static volatile int victim; } public void lock() { int i = ThreadID.get(); victim = i; // wait for the other while (victim == i) {} } CS636 Swarnendu Biswas 12 Filter Algorithm non-CS with n threads level=0 • There are n-1 waiting rooms n-1 threads level=1 called “levels” • One thread gets blocked at each level if many threads try to enter 2 threads level=n-2 CS level=n-1 CS636 Swarnendu Biswas 13 Filter Lock class FilterLock { public void unlock() { int me = ThreadID.get(); int[] level; level[me]= 0; volatile int[] victim; } public FilterLock() { level = new int[n]; victim = new int[n]; for (int i = 0; i < n; i++) { level[i] = 0; } } CS636 Swarnendu Biswas 14 Filter Lock public void lock() { int me = ThreadID.get(); for (int i = 1; i < n; i++) { level[me] = i; // visit level i victim[i] = me; // Thread me is a good guy! // spin while conflict exits while ((∃k != me) level[k] >= i && victim[i] == me) { } } } } CS636 Swarnendu Biswas 15 Fairness • Starvation freedom is good, but maybe threads shouldn’t wait too much… • For example, it would be great if we could order threads by the order in which they performed the first step of the lock() method CS636 Swarnendu Biswas 16 Bounded Waiting • Divide lock() method into two parts • Doorway interval (DA) – finishes in finite steps • Waiting interval (WA) – may take unbounded steps r-Bounded Waiting k j k j+r For threads A and B: if DA DB , then CSA CSB CS636 Swarnendu Biswas 17 Lamport’s Bakery Algorithm class Bakery implements Lock { public Bakery(int n) { flag = new boolean[n]; boolean[] flag; label = new Label[n]; Label[] label; for (int i = 0; i<n; i++) { flag[i] = false; public void unlock() { label[i] = 0; flag[ThreadID.get()] = false; } } } CS636 Swarnendu Biswas 18 Lamport’s Bakery Algorithm (label[i], i) << (label[j], j)) iff label[i] < label[j] or label[i] = label[j] and i < j public void lock() { int i = ThreadID.get(); flag[i] = true; label[i] = max(label[0], …, label[n-1]) + 1; while ((∃k != i) flag[k] && (label[k], k) << (label[i],i)) {} } } CS636 Swarnendu Biswas 19 Lamport’s Fast Lock • Programs with highly contended locks are likely to not scale • Insight: Ideally spin locks should be free of contention • Idea • Two lock fields x and y • Acquire: Thread t writes its id to x and y and checks for intervening writes CS636 Swarnendu Biswas 20 Lamport’s Fast Lock class LFL implements Lock { public void unlock() { private int x, y; y = ⊥; boolean[] trying; trying[ThreadID.get()] = false; } LFL() { y = ⊥; for (int i = 0; i<n; i++) { trying[i] = false; } } CS636 Swarnendu Biswas 21 Lamport’s Fast Lock public void lock() { if (x != self) { int self = ThreadID.get(); trying[self] = false; start: for (i ∈ T) { trying[self] = true; while (trying[i] == true) { x = self; // spin if (y != ⊥) { } trying[self] = false; } while (y != ⊥) {} // spin if (y != self) { goto start; while (y != ⊥) {} // spin } goto start; y = self; } } }} CS636 Swarnendu Biswas 22 Evaluation Lock Performance • Lock acquisition latency • Space overhead • Fairness • Bus traffic CS636 Swarnendu Biswas 23 Atomic Instructions in Hardware CS636 Swarnendu Biswas 24 Hardware Locks • Locks can be completely supported by hardware • Not popular on bus-based machines • Ideas: • Have a set of lock lines on the bus, processor wanting the lock asserts the line, others wait, priority circuit used for arbitrating • Special lock registers, processors wanting the lock acquired ownership of the registers • What could be some problems? CS636 Swarnendu Biswas 25 Common Atomic (RMW) Primitives test_and_set [x86, SPARC] swap [x86, SPARC] bool TAS(bool* loc): word Swap(word* a, word b): atomic { atomic { tmp := *loc; tmp := *a; *loc := true; *a := b; return tmp; return tmp; } } fetch_and_inc [uncommon] fetch_and_add [uncommon] int FAI(int* loc): int FAA(int* loc, int n): atomic { atomic { tmp := *loc; tmp := *loc; *loc := tmp+1; *loc := tmp+n; return tmp; return tmp; } } CS636 Swarnendu Biswas 26 Common Atomic (RMW) Instructions compare_and_swap [x86, IA-64, SPARC] bool CAS(word* loc, world old, word new): atomic { res := (*loc == old); if (res) *loc := new; return res; } CS636 Swarnendu Biswas 27 Common Atomic (RMW) Instructions compare_and_swap [x86, IA-64, SPARC] bool CAS(word* loc, world old, word new): atomic { res := (*loc == old); if (res) *loc := new; return res; } CS636 Swarnendu Biswas 28 Common Atomic (RMW) Instructions load_linked/store_conditional [POWER, MIPS, ARM] word LL(word* a): atomic { remember a; return *a; } bool SC(word* a, word w): atomic { res := (a is remembered, and has not been evicted since LL) if (res) *a = w; return res; } CS636 Swarnendu Biswas 29 Common Atomic (RMW) Instructions load_linked/store_conditional [POWER, MIPS, ARM] word LL(word* a): atomic { remember a; return *a; } bool SC(word* a, word w): atomic { res := (a is remembered, and has not been evicted since LL) if (res) *a = w; return res; } CS636 Swarnendu Biswas 30 ABA Problem void push(node** top, node* new): node* pop(node** top): node* old node* old, new repeat repeat old := *top old := *top new->next := old if old = null return null until CAS(top, old, new) new := old->next until CAS(top, old, new) return old top A C CS636 Swarnendu Biswas 31 ABA Problem void push(node** top, node* new): node* pop(node** top): node* old node* old, new repeat repeat old := *top old := *top new->next := old if old = null return null until CAS(top, old, new) new := old->next until CAS(top, old, new) return old top A C top A B C CS636 Swarnendu Biswas 32 ABA Problem void push(node** top, node* new): node* pop(node** top): node* old node* old, new repeattop A C repeat old := *top old := *top new->next := old if old = null return null until CAS(top, old, new) new := old->next top A B until CAS(top, Cold, new) return old top B C CS636 Swarnendu Biswas 33 Common Atomic (RMW) Instructions compare_and_swap load_linked/store_conditional • Cannot detect ABA • Guaranteed to fail • SC can experience spurious failures • E.g., Cache miss, branch misprediction CS636 Swarnendu Biswas 34 Common Atomic (RMW) Instructions load_linked/store_conditional [POWER, MIPS, ARM] word LL(word* a): atomic { remember a; return *a; } bool SC(word* a, word w): atomic { res := (a is remembered, and has not been evicted since LL) if (res) *a = w; return res; } CS636 Swarnendu Biswas 35 Centralized Mutual Exclusion Algorithms CS636 Swarnendu Biswas 36 Test-And-Set • Atomically tests and sets a word bool TAS(bool* loc) { • For example, swaps one for zero bool res; and returns the old value atomic { res = *loc; • java.util.concurrent.Atomi *loc = true; cBoolean::getAndSet(bool } val) return res; } • Bus traffic? • Fairness? CS636 Swarnendu Biswas 37 Spin Lock
Recommended publications
  • Process Synchronisation Background (1)
    Process Synchronisation Background (1) Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Producer Consumer Background (2) Race condition count++ could be implemented as register1 = count register1 = register1 + 1 count = register1 count- - could be implemented as register2 = count register2 = register2 - 1 count = register2 Consider this execution interleaving with ―count = 5‖ initially: S0: producer execute register1 = count {register1 = 5} S1: producer execute register1 = register1 + 1 {register1 = 6} S2: consumer execute register2 = count {register2 = 5} S3: consumer execute register2 = register2 - 1 {register2 = 4} S4: producer execute count = register1 {count = 6 } S5: consumer execute count = register2 {count = 4} Solution: ensure that only one process at a time can manipulate variable count Avoid interference between changes Critical Section Problem Critical section: a segment of code in which a process may be changing Process structure common variables ◦ Only one process is allowed to be executing in its critical section at any moment in time Critical section problem: design a protocol for process cooperation Requirements for a solution ◦ Mutual exclusion ◦ Progress ◦ Bounded waiting No assumption can be made about the relative speed of processes Handling critical sections in OS ◦ Pre-emptive kernels (real-time programming, more responsive) Linux from 2.6, Solaris, IRIX ◦ Non-pre-emptive kernels (free from race conditions) Windows XP, Windows 2000, traditional UNIX kernel, Linux prior 2.6 Peterson’s Solution Two process solution Process Pi ◦ Mutual exclusion is preserved? ◦ The progress requirements is satisfied? ◦ The bounded-waiting requirement is met? Assumption: LOAD and STORE instructions are atomic, i.e.
    [Show full text]
  • Gnu Smalltalk Library Reference Version 3.2.5 24 November 2017
    gnu Smalltalk Library Reference Version 3.2.5 24 November 2017 by Paolo Bonzini Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". 1 3 1 Base classes 1.1 Tree Classes documented in this manual are boldfaced. Autoload Object Behavior ClassDescription Class Metaclass BlockClosure Boolean False True CObject CAggregate CArray CPtr CString CCallable CCallbackDescriptor CFunctionDescriptor CCompound CStruct CUnion CScalar CChar CDouble CFloat CInt CLong CLongDouble CLongLong CShort CSmalltalk CUChar CByte CBoolean CUInt CULong CULongLong CUShort ContextPart 4 GNU Smalltalk Library Reference BlockContext MethodContext Continuation CType CPtrCType CArrayCType CScalarCType CStringCType Delay Directory DLD DumperProxy AlternativeObjectProxy NullProxy VersionableObjectProxy PluggableProxy SingletonProxy DynamicVariable Exception Error ArithmeticError ZeroDivide MessageNotUnderstood SystemExceptions.InvalidValue SystemExceptions.EmptyCollection SystemExceptions.InvalidArgument SystemExceptions.AlreadyDefined SystemExceptions.ArgumentOutOfRange SystemExceptions.IndexOutOfRange SystemExceptions.InvalidSize SystemExceptions.NotFound SystemExceptions.PackageNotAvailable SystemExceptions.InvalidProcessState SystemExceptions.InvalidState
    [Show full text]
  • Learning Javascript Design Patterns
    Learning JavaScript Design Patterns Addy Osmani Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo Learning JavaScript Design Patterns by Addy Osmani Copyright © 2012 Addy Osmani. All rights reserved. Revision History for the : 2012-05-01 Early release revision 1 See http://oreilly.com/catalog/errata.csp?isbn=9781449331818 for release details. ISBN: 978-1-449-33181-8 1335906805 Table of Contents Preface ..................................................................... ix 1. Introduction ........................................................... 1 2. What is a Pattern? ...................................................... 3 We already use patterns everyday 4 3. 'Pattern'-ity Testing, Proto-Patterns & The Rule Of Three ...................... 7 4. The Structure Of A Design Pattern ......................................... 9 5. Writing Design Patterns ................................................. 11 6. Anti-Patterns ......................................................... 13 7. Categories Of Design Pattern ............................................ 15 Creational Design Patterns 15 Structural Design Patterns 16 Behavioral Design Patterns 16 8. Design Pattern Categorization ........................................... 17 A brief note on classes 17 9. JavaScript Design Patterns .............................................. 21 The Creational Pattern 22 The Constructor Pattern 23 Basic Constructors 23 Constructors With Prototypes 24 The Singleton Pattern 24 The Module Pattern 27 iii Modules 27 Object Literals 27 The Module Pattern
    [Show full text]
  • Bespoke Tools: Adapted to the Concepts Developers Know
    Bespoke Tools: Adapted to the Concepts Developers Know Brittany Johnson, Rahul Pandita, Emerson Murphy-Hill, and Sarah Heckman Department of Computer Science North Carolina State University, Raleigh, NC, USA {bijohnso, rpandit}@ncsu.edu, {emerson, heckman}@csc.ncsu.edu ABSTRACT Such manual customization is undesirable for several rea- Even though different developers have varying levels of ex- sons. First, to choose among alternative tools, a developer pertise, the tools in one developer's integrated development must be aware that alternatives exist, yet lack of awareness environment (IDE) behave the same as the tools in every is a pervasive problem in complex software like IDEs [3]. other developers' IDE. In this paper, we propose the idea of Second, even after being aware of alternatives, she must be automatically customizing development tools by modeling able to intelligently choose which tool will be best for her. what a developer knows about software concepts. We then Third, if a developer's situation changes and she recognizes sketch three such \bespoke" tools and describe how devel- that the tool she is currently using is no longer the optimal opment data can be used to infer what a developer knows one, she must endure the overhead of switching to another about relevant concepts. Finally, we describe our ongoing ef- tool. Finally, customization takes time, time that is spent forts to make bespoke program analysis tools that customize fiddling with tools rather than developing software. their notifications to the developer using them. 2. WHAT IS THE NEW IDEA? Categories and Subject Descriptors Our idea is bespoke tools: tools that automatically fit D.2.6 [Software Engineering]: Programming Environments| themselves to the developer using them.
    [Show full text]
  • An Analysis of the Dynamic Behavior of Javascript Programs
    An Analysis of the Dynamic Behavior of JavaScript Programs Gregor Richards Sylvain Lebresne Brian Burg Jan Vitek S3 Lab, Department of Computer Science, Purdue University, West Lafayette, IN fgkrichar,slebresn,bburg,[email protected] Abstract becoming a general purpose computing platform with office appli- The JavaScript programming language is widely used for web cations, browsers and development environments [15] being devel- programming and, increasingly, for general purpose computing. oped in JavaScript. It has been dubbed the “assembly language” of the Internet and is targeted by code generators from the likes As such, improving the correctness, security and performance of 2;3 JavaScript applications has been the driving force for research in of Java and Scheme [20]. In response to this success, JavaScript type systems, static analysis and compiler techniques for this lan- has started to garner academic attention and respect. Researchers guage. Many of these techniques aim to reign in some of the most have focused on three main problems: security, correctness and dynamic features of the language, yet little seems to be known performance. Security is arguably JavaScript’s most pressing prob- about how programmers actually utilize the language or these fea- lem: a number of attacks have been discovered that exploit the lan- tures. In this paper we perform an empirical study of the dynamic guage’s dynamism (mostly the ability to access and modify shared behavior of a corpus of widely-used JavaScript programs, and an- objects and to inject code via eval). Researchers have proposed ap- alyze how and why the dynamic features are used.
    [Show full text]
  • Scalable NUMA-Aware Blocking Synchronization Primitives
    Scalable NUMA-aware Blocking Synchronization Primitives Sanidhya Kashyap, Changwoo Min, Taesoo Kim The rise of big NUMA machines 'i The rise of big NUMA machines 'i The rise of big NUMA machines 'i Importance of NUMA awareness NUMA node 1 NUMA node 2 NUMA oblivious W1 W2 W3 W4 W6 W5 W6 W5 W3 W1 W4 L W2 File Importance of NUMA awareness NUMA node 1 NUMA node 2 NUMA oblivious W1 W2 W3 W4 W6 W5 W6 W5 W3 W1 W4 NUMA aware/hierarchical L W2 W1 W6 W2 W3 W4 W5 File Importance of NUMA awareness NUMA node 1 NUMA node 2 NUMA oblivious W1 W2 W3 W4 W6 W5 W6 W5 W3 W1 W4 NUMA aware/hierarchical L W2 W1 W6 W2 W3 W4 W5 File Idea: Make synchronization primitives NUMA aware! Lock's research efforts and their use Lock's research efforts Linux kernel lock Dekker's algorithm (1962) adoption / modification Semaphore (1965) Lamport's bakery algorithm (1974) Backoff lock (1989) Ticket lock (1991) MCS lock (1991) HBO lock (2003) Hierarchical lock – HCLH (2006) Flat combining NUMA lock (2011) Remote Core locking (2012) Cohort lock (2012) RW cohort lock (2013) Malthusian lock (2014) HMCS lock (2015) AHMCS lock(2016) Lock's research efforts and their use Lock's research efforts Linux kernel lock Dekker's algorithm (1962) adoption / modification Semaphore (1965) Lamport's bakery algorithm (1974) Backoff lock (1989) Ticket lock (1991) MCS lock (1991) HBO lock (2003) Hierarchical lock – HCLH (2006) Flat combining NUMA lock (2011) Remote Core locking (2012) NUMA- Cohort lock (2012) aware RW cohort lock (2013) locks Malthusian lock (2014) HMCS lock (2015) AHMCS lock(2016)
    [Show full text]
  • Platform SDK Developer's Guide
    Platform SDK Developer's Guide Platform SDK 9.0.x 3/6/2020 Table of Contents Welcome to the Developer's Guide! 4 Introductory Topics 6 Introducing the Platform SDK 7 Architecture of the Platform SDK 12 Connecting to a Server 14 Configuring Platform SDK Channel Encoding for String Values 32 Using the Warm Standby Application Block 33 Using the Application Template Application Block 42 Using the Cluster Protocol Application Block 74 Event Handling 88 Setting up Logging in Platform SDK 100 Additional Logging Features 106 Log4j2 Configuration with the Application Template Application Block 116 Advanced Platform SDK Topics 132 Using Kerberos Authentication in Platform SDK 133 Secure connections using TLS 137 Quick Start 143 TLS and the Platform SDK Commons Library 147 TLS and the Application Template Application Block 160 Configuring TLS Parameters in Configuration Manager 167 Using and Configuring Security Providers 190 OpenSSL Configuration File 201 Use Cases 208 Using and Configuring TLS Protocol Versions 211 Lazy Parsing of Message Attributes 214 Log Filtering 218 Hide or Tag Sensitive Data in Logs 230 Profiling and Performance Services 237 IPv6 Resolution 243 Managing Protocol Configuration 248 Friendly Reaction to Unsupported Messages 252 Creating Custom Protocols 258 JSON Support 267 Working with Custom Servers 276 Bidirectional Messaging 282 Hide Message Attributes in Logs 287 Resources Releasing in an Application Container 289 Transport Layer Substitution 292 Server-Specific Overviews 301 Telephony (T-Server) 302 Introduction to TLib
    [Show full text]
  • Design Patterns for Parsing Dung “Zung” Nguyen Mathias Ricken Stephen Wong Dept
    Design Patterns for Parsing Dung “Zung” Nguyen Mathias Ricken Stephen Wong Dept. of Computer Science Dept. of Computer Science Dept. of Computer Science Rice University Rice University Rice University Houston, TX 77005 Houston, TX 77005 Houston, TX 77005 +1 713-348-3835 +1 713-348-3836 +1 713-348-3814 [email protected] [email protected] [email protected] ABSTRACT be effective, they must progress normally yet quickly to cover We provide a systematic transformation of an LL(1) grammar to topics that are complex enough to make a compelling case for an object model that consists of OOP (see for instance, [2][3]). A wealth of problems in various • an object structure representing the non-terminal symbols and phases of a compiler can be appropriately modeled as object- their corresponding grammar production rules, oriented systems. However, such problems are rarely discussed at the introductory level in current computer science curricula. • a union of classes representing the terminal symbols (tokens). A quick tour of web sites and extant textbooks [4][5][6][7] seems We present a variant form of the visitor pattern and apply it to the to indicate that context-free grammars (CFG) and their related above union of token classes to model a predictive recursive topics are usually relegated to upper division courses in descent parser on the given grammar. Parsing a non-terminal is programming languages and compiler construction. Efforts have represented by a visitor to the tokens. For non-terminals that have been made to introduce object-oriented design patterns such as the more than one production rule, the corresponding visitors are composite and visitor patterns into such courses at the semantic chained together according to the chain of responsibility pattern in analysis phases but not at the syntax analysis phase [5][8].
    [Show full text]
  • Pharo by Example
    Portland State University PDXScholar Computer Science Faculty Publications and Computer Science Presentations 2009 Pharo by Example Andrew P. Black Portland State University, [email protected] Stéphane Ducasse Oscar Nierstrasz University of Berne Damien Pollet University of Lille Damien Cassou See next page for additional authors Let us know how access to this document benefits ouy . Follow this and additional works at: http://pdxscholar.library.pdx.edu/compsci_fac Citation Details Black, Andrew, et al. Pharo by example. 2009. This Book is brought to you for free and open access. It has been accepted for inclusion in Computer Science Faculty Publications and Presentations by an authorized administrator of PDXScholar. For more information, please contact [email protected]. Authors Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz, Damien Pollet, Damien Cassou, and Marcus Denker This book is available at PDXScholar: http://pdxscholar.library.pdx.edu/compsci_fac/108 Pharo by Example Andrew P. Black Stéphane Ducasse Oscar Nierstrasz Damien Pollet with Damien Cassou and Marcus Denker Version of 2009-10-28 ii This book is available as a free download from http://PharoByExample.org. Copyright © 2007, 2008, 2009 by Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz and Damien Pollet. The contents of this book are protected under Creative Commons Attribution-ShareAlike 3.0 Unported license. You are free: to Share — to copy, distribute and transmit the work to Remix — to adapt the work Under the following conditions: Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
    [Show full text]
  • Object-Oriented Design Patterns
    Object-Oriented Design Patterns David Janzen EECS 816 Object-Oriented Software Development University of Kansas Outline • Introduction – Design Patterns Overview – Strategy as an Early Example – Motivation for Creating and Using Design Patterns – History of Design Patterns • Gang of Four (GoF) Patterns – Creational Patterns – Structural Patterns – Behavioral Patterns Copyright © 2006 by David S. 2 Janzen. All rights reserved. What are Design Patterns? • In its simplest form, a pattern is a solution to a recurring problem in a given context • Patterns are not created, but discovered or identified • Some patterns will be familiar? – If you’ve been designing and programming for long, you’ve probably seen some of the patterns we will discuss – If you use Java Foundation Classes (Swing), Copyright © 2006 by David S. 3 you have certaJiannzleyn. Aulls rieghdts rsesoervmed.e design patterns Design Patterns Definition1 • Each pattern is a three-part rule, which expresses a relation between – a certain context, – a certain system of forces which occurs repeatedly in that context, and – a certain software configuration which allows these forces to resolve themselves 1. Dick Gabriel, http://hillside.net/patterns/definition.html Copyright © 2006 by David S. 4 Janzen. All rights reserved. A Good Pattern1 • Solves a problem: – Patterns capture solutions, not just abstract principles or strategies. • Is a proven concept: – Patterns capture solutions with a track record, not theories or speculation 1. James O. Coplien, http://hillside.net/patterns/definition.html Copyright © 2006 by David S. 5 Janzen. All rights reserved. A Good Pattern • The solution isn't obvious: – Many problem-solving techniques (such as software design paradigms or methods) try to derive solutions from first principles.
    [Show full text]
  • IBM ILOG CPLEX Optimization Studio OPL Language Reference Manual
    IBM IBM ILOG CPLEX Optimization Studio OPL Language Reference Manual Version 12 Release 7 Copyright notice Describes general use restrictions and trademarks related to this document and the software described in this document. © Copyright IBM Corp. 1987, 2017 US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Trademarks IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml. Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, and/or other countries. Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. UNIX is a registered trademark of The Open Group in the United States and other countries. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates. Other company, product, or service names may be trademarks or service marks of others. © Copyright IBM Corporation 1987, 2017. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Figures ............... v Limitations on constraints ........ 59 Formal parameters ...........
    [Show full text]
  • Non-Scalable Locks Are Dangerous
    Non-scalable locks are dangerous Silas Boyd-Wickizer, M. Frans Kaashoek, Robert Morris, and Nickolai Zeldovich MIT CSAIL Abstract more cores. The paper presents a predictive model of non-scalable lock performance that explains this phe- Several operating systems rely on non-scalable spin locks nomenon. for serialization. For example, the Linux kernel uses A third element of the argument is that critical sections ticket spin locks, even though scalable locks have better which appear to the eye to be very short, perhaps only theoretical properties. Using Linux on a 48-core ma- a few instructions, can nevertheless trigger performance chine, this paper shows that non-scalable locks can cause collapses. The paper’s model explains this phenomenon dramatic collapse in the performance of real workloads, as well. even for very short critical sections. The nature and sud- den onset of collapse are explained with a new Markov- Naturally we argue that one should use scalable locks [1, based performance model. Replacing the offending non- 7, 9], particularly in operating system kernels where scalable spin locks with scalable spin locks avoids the the workloads and levels of contention are hard to con- collapse and requires modest changes to source code. trol. As a demonstration, we replaced Linux’s spin locks with scalable MCS locks [9] and re-ran the software that caused performance collapse. For 3 of the 4 benchmarks 1 Introduction the changes in the kernel were simple. For the 4th case the changes were more involved because the directory It is well known that non-scalable locks, such as simple cache uses a complicated locking plan and the directory spin locks, have poor performance when highly con- cache in general is complicated.
    [Show full text]