Design Patterns and Refactoring

Size: px
Start display at page:

Download "Design Patterns and Refactoring"

Transcription

1 Singleton Oliver Haase HTWG Konstanz 1 / 19

2 Description I Classification: object based creational pattern Puropse: ensure that a class can be instantiated exactly once provide global access point to single instance Application Examples: exactly one driver for a piece if hardware (e.g. printer) exactly one socket listener that receives incoming requests application that can be started only once global event queue for discrete event simulation 2 / 19

3 Description II Structure: Members: Singleton responsible for creation of the instance provides static operation for access to the instance Interactions: clients access singleton instance through getinstance operation 3 / 19

4 Description III Alternative: Class with static variables and static methods Drawbacks: 4 / 19

5 Description III Alternative: Class with static variables and static methods Drawbacks: Java interfaces cannot contain static methods class cannot be hidden behind interface each method invocation contains class name undermines polymorphism 4 / 19

6 5 / 19

7 Singleton implementation with Lazy Instantiation 1 public c l a s s MySingleton { 2 private s t a t i c MySingleton i n s t a n c e = n u l l ; 3 private MySingleton () { public s t a t i c MySingleton g e t I n s t a n c e () { 7 i f ( i n s t a n c e == n u l l ) { 8 i n s t a n c e = new M y S i n g l e t o n ( ) ; 9 10 return instance ; / 19

8 Singleton implementation with Lazy Instantiation 1 public c l a s s MySingleton { 2 private s t a t i c MySingleton i n s t a n c e = n u l l ; 3 private MySingleton () { public s t a t i c MySingleton g e t I n s t a n c e () { 7 i f ( i n s t a n c e == n u l l ) { 8 i n s t a n c e = new M y S i n g l e t o n ( ) ; 9 10 return instance ; Problem: Can lead to several instances if thread gets interrupted between lines 7 and 8 not thread-safe! 5 / 19

9 Resolve concurrency problem through synchronization: public c l a s s MySingleton { private s t a t i c MySingleton i n s t a n c e = n u l l ; private MySingleton () { public s t a t i c synchronized MySingleton g e t I n s t a n c e () { i f ( i n s t a n c e == n u l l ) { i n s t a n c e = new M y S i n g l e t o n ( ) ; return instance ; 6 / 19

10 Problem: Only first call of getinstance needs to be synchronized: unnecessary reduction of concurrency synchronized Methods always slower than unsynchronized methods: test program with 109 sequential getinstance calls on Mac Mini, 2 GHz Intel Core 2 Duo, 1 GB RAM, 120 GB hard drive: unsynchronized synchronized 4 sec. 58 sec. 7 / 19

11 with Checked Locking 1 public c l a s s MySingleton { 2 private s t a t i c MySingleton i n s t a n c e = n u l l ; 3 private MySingleton () { public s t a t i c MySingleton g e t I n s t a n c e () { 7 i f ( i n s t a n c e == n u l l ) { 8 synchronized ( MySingleton. c l a s s ) { 9 i n s t a n c e = new M y S i n g l e t o n ( ) ; return instance ; / 19

12 Scenario: Thread1 gets interrupted between lines 8 and 9 holds monitor of MySingleton class object, no singleton instance created yet. Thread2 passes 7, waits at 8 for Thread1 Thread1 finishes, creates singleton instance Thread2 finishes, creates second singleton instance not thread-safe! 9 / 19

13 Solution attempt using Double-Checked-Locking-(Anti-)Pattern: 1 public c l a s s MySingleton { 2 private s t a t i c MySingleton i n s t a n c e = n u l l ; 3 private MySingleton () { public s t a t i c MySingleton g e t I n s t a n c e () { 7 i f ( i n s t a n c e == n u l l ) { 8 synchronized ( MySingleton. c l a s s ) { 9 i f ( i n s t a n c e == n u l l ) { 10 i n s t a n c e = new M y S i n g l e t o n ( ) ; return instance ; Works well or does it? 10 / 19

14 Problem: Thread scheduling happens on the level of byte code, not on the Java source code level... object creation in line 10 i n s t a n c e = new M y S i n g l e t o n ( ) ; is mapped to the following pseudo byte code 1 ptrmemory = a l l o c a t e M e m o r y ( ) 2 a s s i g n M e m o r y ( i n s t a n c e, ptrmemory ) 3 callmysingletonconstructor ( instance ) If scheduling takes place between lines 2 and 3 then instance!= null, even though instance has not been properly initialized Thread2 might return uninitialized object instance, if thread 10 is interrupted within line 10! 11 / 19

15 The simple things are often the best or: Life can be that simple! fully functional, performant solution: public c l a s s MySingleton { p r i v a t e s t a t i c M y S i n g l e t o n i n s t a n c e = new M y S i n g l e t o n ( ) ; private MySingleton () { public s t a t i c MySingleton g e t I n s t a n c e () { return instance ; 12 / 19

16 Consequences of the simple implementation 13 / 19

17 Consequences of the simple implementation Singleton instance is created (exactly once) at class loading time even if it will never be used but: this rarely happens because class loading is usually triggered by usage rather small damage Time consumption at loading rsther than at first usage neither better nor worse, only different... potential drawback: class loading order hardly predictable Problem, if one singleton instance is needed to create another 13 / 19

18 Usage Joi 1 programming language supports singleton pattern: s i n g l e t o n component MyComponent p r o v i d e s M y I n t e r f a c e { The current Joi implementation maps the Joi code to corresponding Java code. Reason: Joi doesn t support static class members static variables are modelled as members of a singleton class frequent usage of the singleton pattern Java Webstart: Technology for the dynamic download, execution and updating of applications 1 more informationen at haase/hp/joi.html and in [von Drachenfels, Haase, Walter. Joi - eine Java Spracherweiterung zur Reduzierung von Codeabha ngigkeiten. In HTWG Forum, 2008/2009] 14 / 19

19 Singleton Additional Considerations Sometimes, a singleton object needs to be configured at creation time (or at the time of first usage) Example: Socket listener that needs to listen on certain port Possible Realizations: add parameters to getinstance method: p u b l i c c l a s s CS1 { p r i v a t e s t a t i c CS1 i n s t a n c e = new CS1 ( ) ; private int state ; p r i v a t e CS1 ( ) { private void config ( int state ) { this. state = state ; p u b l i c s t a t i c CS1 g e t I n s t a n c e ( i n t s t a t e ) { instance. config ( state ); return instance ; params need to be passed into all subsequent getinstance calls 15 / 19

20 Singleton Additional Considerations two overloaded getinstance methods with and w/o parameters p u b l i c c l a s s CS2 { p r i v a t e s t a t i c CS2 i n s t a n c e = new CS1 ( ) ; private int state ; p r i v a t e CS2 ( ) { private void c o n f i g ( i n t s t a t e ) { this. state = state ; p u b l i c s t a t i c CS2 g e t I n s t a n c e ( i n t s t a t e ) { instance. config ( state ); return instance ; p u b l i c s t a t i c CS2 g e t I n s t a n c e ( ) { return instance ; 16 / 19

21 Singleton Additional Considerations getinstance method without params + separate config method; catch repeated config invocations p u b l i c c l a s s CS3 { p r i v a t e s t a t i c CS3 i n s t a n c e = new CS3 ( ) ; private int state ; p r i v a t e boolean c o n f i g u r e d = f a l s e ; p r i v a t e CS3 ( ) { public synchronized void c o n f i g ( i n t s t a t e ) throws E x c e p t i o n { i f ( configured ) throw new E x c e p t i o n ( a l r e a d y c o n f i g u r e d ) ; this. state = state ; t h i s. configured = true ; p u b l i c s t a t i c CS3 g e t I n s t a n c e ( ) { return instance ; 17 / 19

22 Singleton Additional Considerations getinstance method without params + separate static config method, catch repeated and/or missing config invocations p u b l i c c l a s s CS4 { p r i v a t e s t a t i c CS4 i n s t a n c e = new CS4 ( ) ; private int state ; p r i v a t e s t a t i c bo ole an c o n f i g u r e d = f a l s e ; p r i v a t e CS4 ( ) { 18 / 19

23 Singleton Additional Considerations public s t a t i c synchronized void c o n f i g ( i n t s t a t e ) throws E x c e p t i o n { i f ( configured ) { throw new E x c e p t i o n ( a l r e a d y c o n f i g u r e d ) ; instance. state = state ; configured = true ; p u b l i c s t a t i c CS4 g e t I n s t a n c e ( ) throws E x c e p t i o n { i f (! configured ) throw new E x c e p t i o n ( n o t c o n f i g u r e d y e t ) ; return instance ; 19 / 19

Real Time Operating Systems

Real Time Operating Systems Real Time Operating ystems Luca Abeni luca.abeni@unitn.it Interacting Tasks Until now, only independent tasks... A job never blocks or suspends A task only blocks on job termination In real world, jobs

More information

Real Time Operating Systems

Real Time Operating Systems Real Time Operating ystems hared Resources Luca Abeni Credits: Luigi Palopoli, Giuseppe Lipari, and Marco Di Natale cuola uperiore ant Anna Pisa -Italy Real Time Operating ystems p. 1 Interacting Tasks

More information

public void run ( ) { i f ( this. id == 0) System. out. p r i n t ( 3 ) ; bro. j o i n ( ) ; else System. out. p r i n t ( 2 ) ;

public void run ( ) { i f ( this. id == 0) System. out. p r i n t ( 3 ) ; bro. j o i n ( ) ; else System. out. p r i n t ( 2 ) ; 1 Unusual programs 1. Consider the following Java program : public c l a s s Thread2 extends Thread { public int id ; public Thread2 bro ; public Thread2 ( int id, Thread2 bro ) { this. id = id ; this.

More information

Blocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012)

Blocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012) 1 Streams Blocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012) Streams provide a very simple abstraction for determinate parallel computation. The intuition for streams is already present in

More information

SDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version

SDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version SDS developer guide Develop distributed and parallel applications in Java Nathanaël Cottin sds@ncottin.net http://sds.ncottin.net version 0.0.3 Copyright 2007 - Nathanaël Cottin Permission is granted to

More information

CS-206 Concurrency. Lecture 8 Concurrent. Data structures. a b c d. Spring 2015 Prof. Babak Falsafi parsa.epfl.ch/courses/cs206/ remove(c) remove(b)

CS-206 Concurrency. Lecture 8 Concurrent. Data structures. a b c d. Spring 2015 Prof. Babak Falsafi parsa.epfl.ch/courses/cs206/ remove(c) remove(b) CS-206 Concurrency Lecture 8 Concurrent a b c d Data structures Spring 2015 Prof. Babak Falsafi parsa.epfl.ch/courses/cs206/ remove(b) remove(c) Adapted from slides originally developed by Maurice Herlihy

More information

Safety and Liveness. Thread Synchronization: Too Much Milk. Critical Sections. A Really Cool Theorem

Safety and Liveness. Thread Synchronization: Too Much Milk. Critical Sections. A Really Cool Theorem Safety and Liveness Properties defined over an execution of a program Thread Synchronization: Too Much Milk Safety: nothing bad happens holds in every finite execution prefix Windows never crashes No patient

More information

INF Models of concurrency

INF Models of concurrency INF4140 - Models of concurrency Fall 2017 October 17, 2017 Abstract This is the handout version of the slides for the lecture (i.e., it s a rendering of the content of the slides in a way that does not

More information

Thread Specific Storage

Thread Specific Storage Thread Specific Storage The behavioural pattern explained Huib van den Brink Utrecht University hjbrink@cs.uu.nl Abstract While multi-threading can improve the performance of an application, this is not

More information

Scheduling I. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Advanced topics on scheduling

Scheduling I. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Advanced topics on scheduling Scheduling I Today! Introduction to scheduling! Classical algorithms Next Time! Advanced topics on scheduling Scheduling out there! You are the manager of a supermarket (ok, things don t always turn out

More information

Queuing Networks. - Outline of queuing networks. - Mean Value Analisys (MVA) for open and closed queuing networks

Queuing Networks. - Outline of queuing networks. - Mean Value Analisys (MVA) for open and closed queuing networks Queuing Networks - Outline of queuing networks - Mean Value Analisys (MVA) for open and closed queuing networks 1 incoming requests Open queuing networks DISK CPU CD outgoing requests Closed queuing networks

More information

CPU SCHEDULING RONG ZHENG

CPU SCHEDULING RONG ZHENG CPU SCHEDULING RONG ZHENG OVERVIEW Why scheduling? Non-preemptive vs Preemptive policies FCFS, SJF, Round robin, multilevel queues with feedback, guaranteed scheduling 2 SHORT-TERM, MID-TERM, LONG- TERM

More information

Lists, Stacks, and Queues (plus Priority Queues)

Lists, Stacks, and Queues (plus Priority Queues) Lists, Stacks, and Queues (plus Priority Queues) The structures lists, stacks, and queues are composed of similar elements with different operations. Likewise, with mathematics: (Z, +, 0) vs. (Z,, 1) List

More information

CS162 Operating Systems and Systems Programming Lecture 7 Semaphores, Conditional Variables, Deadlocks"

CS162 Operating Systems and Systems Programming Lecture 7 Semaphores, Conditional Variables, Deadlocks CS162 Operating Systems and Systems Programming Lecture 7 Semaphores, Conditional Variables, Deadlocks" September 19, 2012! Ion Stoica! http://inst.eecs.berkeley.edu/~cs162! Recap: Monitors" Monitors represent

More information

Maps performance tips On server: Maintain DB connections, prepared statements (per thread/request!)

Maps performance tips On server: Maintain DB connections, prepared statements (per thread/request!) Announcements Maps performance tips On server: Maintain DB connections, prepared statements (per thread/request!) Use Spark.before, Spark.after to open and close. Use ThreadLocal, or pass the connection

More information

Computer Science Introductory Course MSc - Introduction to Java

Computer Science Introductory Course MSc - Introduction to Java Computer Science Introductory Course MSc - Introduction to Java Lecture 3:,, Pablo Oliveira ENST Outline 1 2 3 Definition An exception is an event that indicates an abnormal condition

More information

TDDB68 Concurrent programming and operating systems. Lecture: CPU Scheduling II

TDDB68 Concurrent programming and operating systems. Lecture: CPU Scheduling II TDDB68 Concurrent programming and operating systems Lecture: CPU Scheduling II Mikael Asplund, Senior Lecturer Real-time Systems Laboratory Department of Computer and Information Science Copyright Notice:

More information

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University Che-Wei Chang chewei@mail.cgu.edu.tw Department of Computer Science and Information Engineering, Chang Gung University } 2017/11/15 Midterm } 2017/11/22 Final Project Announcement 2 1. Introduction 2.

More information

1. Write a program to calculate distance traveled by light

1. Write a program to calculate distance traveled by light G. H. R a i s o n i C o l l e g e O f E n g i n e e r i n g D i g d o h H i l l s, H i n g n a R o a d, N a g p u r D e p a r t m e n t O f C o m p u t e r S c i e n c e & E n g g P r a c t i c a l M a

More information

More on Methods and Encapsulation

More on Methods and Encapsulation More on Methods and Encapsulation Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 31, 2009 H.-T. Lin (NTU CSIE) More on Methods and Encapsulation OOP(even) 03/31/2009 0 / 38 Local Variables Local

More information

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010 More About Methods Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 8-9, 2010 H.-T. Lin (NTU CSIE) More About Methods OOP 03/08-09/2010 0 / 24 Methods: the Basic Method (1/2, Callee s View) 1 p

More information

Sharing Objects. Pieter van den Hombergh. Fontys Hogeschool voor Techniek en Logistiek. February 15, 2017

Sharing Objects. Pieter van den Hombergh. Fontys Hogeschool voor Techniek en Logistiek. February 15, 2017 Pieter van den Hombergh Fontys Hogeschool voor Techniek en Logistiek February 15, 2017 and /FHTenL February 15, 2017 is safe Idioms 1/34 and and is safe Idioms /FHTenL February 15, 2017 2/34 visibility

More information

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20

Object Oriented Software Design (NTU, Class Even, Spring 2009) Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 Final Examination Problem Sheet TIME: 06/16/2009, 14:20 17:20 This is a closed-book exam. Any form of cheating or lying will not be tolerated. Students can get zero scores and/or fail the class and/or

More information

Extensibility Patterns: Extension Access

Extensibility Patterns: Extension Access Design Patterns and Frameworks Dipl.-Medieninf. Christian Piechnick INF 2080 christian.piechnick@tu-dresden.de Exercise Sheet No. 5 Software Technology Group Institute for SMT Department of Computer Science

More information

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014

Clojure Concurrency Constructs, Part Two. CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014 Clojure Concurrency Constructs, Part Two CSCI 5828: Foundations of Software Engineering Lecture 13 10/07/2014 1 Goals Cover the material presented in Chapter 4, of our concurrency textbook In particular,

More information

Shared resources. Sistemi in tempo reale. Giuseppe Lipari. Scuola Superiore Sant Anna Pisa -Italy

Shared resources. Sistemi in tempo reale. Giuseppe Lipari. Scuola Superiore Sant Anna Pisa -Italy istemi in tempo reale hared resources Giuseppe Lipari cuola uperiore ant Anna Pisa -Italy inher.tex istemi in tempo reale Giuseppe Lipari 7/6/2005 12:35 p. 1/21 Interacting tasks Until now, we have considered

More information

Information System Design IT60105

Information System Design IT60105 n IT60105 Lecture 13 Statechart Diagrams Lecture #13 What is a Statechart diagram? Basic components in a state-chart diagram and their notations Examples: Process Order in OLP system What is a Statechart

More information

Lecture 13. Real-Time Scheduling. Daniel Kästner AbsInt GmbH 2013

Lecture 13. Real-Time Scheduling. Daniel Kästner AbsInt GmbH 2013 Lecture 3 Real-Time Scheduling Daniel Kästner AbsInt GmbH 203 Model-based Software Development 2 SCADE Suite Application Model in SCADE (data flow + SSM) System Model (tasks, interrupts, buses, ) SymTA/S

More information

arxiv: v1 [cs.se] 10 Jan 2018

arxiv: v1 [cs.se] 10 Jan 2018 To Pool or Not To Pool? Revisiting an Old Pattern Ioannis T. Christou Athens Information Technology, 15125 Marousi, Greece Sofoklis Efremidis Athens Information Technology, 15125 Marousi, Greece arxiv:1801.03763v1

More information

CEC 450 Real-Time Systems

CEC 450 Real-Time Systems E 450 Real-ime Systems Lecture 4 Rate Monotonic heory Part September 7, 08 Sam Siewert Quiz Results 93% Average, 75 low, 00 high Goal is to learn what you re not learning yet Motivation to keep up with

More information

PySy: A Python Package for Enhanced Concurrent Programming. TODD WILLIAMSON B.S (University of California at Davis) 2007 THESIS

PySy: A Python Package for Enhanced Concurrent Programming. TODD WILLIAMSON B.S (University of California at Davis) 2007 THESIS PySy: A Python Package for Enhanced Concurrent Programming By TODD WILLIAMSON B.S (University of California at Davis) 2007 THESIS Submitted in partial satisfaction of the requirements for the degree of

More information

CSE 380 Computer Operating Systems

CSE 380 Computer Operating Systems CSE 380 Computer Operating Systems Instructor: Insup Lee & Dianna Xu University of Pennsylvania, Fall 2003 Lecture Note 3: CPU Scheduling 1 CPU SCHEDULING q How can OS schedule the allocation of CPU cycles

More information

Lecture 5: Sep. 23 &25

Lecture 5: Sep. 23 &25 CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 5: Sep. 23 &25 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 5.1 Doubly Linked

More information

Scheduling I. Today Introduction to scheduling Classical algorithms. Next Time Advanced topics on scheduling

Scheduling I. Today Introduction to scheduling Classical algorithms. Next Time Advanced topics on scheduling Scheduling I Today Introduction to scheduling Classical algorithms Next Time Advanced topics on scheduling Scheduling out there You are the manager of a supermarket (ok, things don t always turn out the

More information

Techniques of Java Programming

Techniques of Java Programming Legi-Nr.:... Techniques of Java Programming ETH Zurich Date: 9 May 008 Family name, first name:... Student number:... I confirm with my signature, that I was able to take this exam under regular circumstances

More information

Performance Analysis of Lattice QCD Application with APGAS Programming Model

Performance Analysis of Lattice QCD Application with APGAS Programming Model Performance Analysis of Lattice QCD Application with APGAS Programming Model Koichi Shirahata 1, Jun Doi 2, Mikio Takeuchi 2 1: Tokyo Institute of Technology 2: IBM Research - Tokyo Programming Models

More information

From High-Level Component-Based Models to Distributed Implementations

From High-Level Component-Based Models to Distributed Implementations From High-Level Component-Based Models to Distributed Implementations Borzoo Bonakdarpour Marius Bozga Mohamad Jaber Jean Quilbeuf Joseph Sifakis VERIMAG, Centre Équation, 2 avenue de Vignate, 38610, Gières,

More information

Outline. PeerSim: Informal introduction. Resources. What is PeerSim? Alberto Montresor Gianluca Ciccarelli

Outline. PeerSim: Informal introduction. Resources. What is PeerSim? Alberto Montresor Gianluca Ciccarelli Outline PeerSim: Informal introduction Alberto Montresor Gianluca Ciccarelli Networking group - University of Trento April 3, 2009 1 2 files structure 3 1 / 45 2 / 45 Resources What is PeerSim? These slides

More information

Multicore Semantics and Programming

Multicore Semantics and Programming Multicore Semantics and Programming Peter Sewell Tim Harris University of Cambridge Oracle October November, 2015 p. 1 These Lectures Part 1: Multicore Semantics: the concurrency of multiprocessors and

More information

Distributed Systems Part II Solution to Exercise Sheet 10

Distributed Systems Part II Solution to Exercise Sheet 10 Distributed Computing HS 2012 Prof. R. Wattenhofer / C. Decker Distributed Systems Part II Solution to Exercise Sheet 10 1 Spin Locks A read-write lock is a lock that allows either multiple processes to

More information

Synchronous Reactive Systems

Synchronous Reactive Systems Synchronous Reactive Systems Stephen Edwards sedwards@synopsys.com Synopsys, Inc. Outline Synchronous Reactive Systems Heterogeneity and Ptolemy Semantics of the SR Domain Scheduling the SR Domain 2 Reactive

More information

Real-Time Scheduling and Resource Management

Real-Time Scheduling and Resource Management ARTIST2 Summer School 2008 in Europe Autrans (near Grenoble), France September 8-12, 2008 Real-Time Scheduling and Resource Management Lecturer: Giorgio Buttazzo Full Professor Scuola Superiore Sant Anna

More information

From Sequential Circuits to Real Computers

From Sequential Circuits to Real Computers 1 / 36 From Sequential Circuits to Real Computers Lecturer: Guillaume Beslon Original Author: Lionel Morel Computer Science and Information Technologies - INSA Lyon Fall 2017 2 / 36 Introduction What we

More information

Go Tutorial. Ian Lance Taylor. Introduction. Why? Language. Go Tutorial. Ian Lance Taylor. GCC Summit, October 27, 2010

Go Tutorial. Ian Lance Taylor. Introduction. Why? Language. Go Tutorial. Ian Lance Taylor. GCC Summit, October 27, 2010 GCC Summit, October 27, 2010 Go Go is a new experimental general purpose programming language. Main developers are: Russ Cox Robert Griesemer Rob Pike Ken Thompson It was released as free software in November

More information

CPU scheduling. CPU Scheduling

CPU scheduling. CPU Scheduling EECS 3221 Operating System Fundamentals No.4 CPU scheduling Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University CPU Scheduling CPU scheduling is the basis of multiprogramming

More information

Distributed Algorithms Time, clocks and the ordering of events

Distributed Algorithms Time, clocks and the ordering of events Distributed Algorithms Time, clocks and the ordering of events Alberto Montresor University of Trento, Italy 2016/04/26 This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International

More information

Agreement. Today. l Coordination and agreement in group communication. l Consensus

Agreement. Today. l Coordination and agreement in group communication. l Consensus Agreement Today l Coordination and agreement in group communication l Consensus Events and process states " A distributed system a collection P of N singlethreaded processes w/o shared memory Each process

More information

Marwan Burelle. Parallel and Concurrent Programming. Introduction and Foundation

Marwan Burelle.  Parallel and Concurrent Programming. Introduction and Foundation and and marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Outline 1 2 and 3 and Evolutions and Next evolutions in processor tends more on more on growing of cores number GPU and similar extensions

More information

Applying Architectural Patterns for Parallel Programming Solving the One-dimensional Heat Equation

Applying Architectural Patterns for Parallel Programming Solving the One-dimensional Heat Equation Applying Architectural Patterns for Parallel Programming Solving the One-dimensional Heat Equation Jorge L. Ortega Arjona Departamento de Matemáticas Facultad de Ciencias, UNAM. jloa@ciencias.unam.mx Abstract

More information

CHAPTER 5 - PROCESS SCHEDULING

CHAPTER 5 - PROCESS SCHEDULING CHAPTER 5 - PROCESS SCHEDULING OBJECTIVES To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various CPU-scheduling algorithms To discuss evaluation criteria

More information

13 Concurrent Programming using Tasks and Services

13 Concurrent Programming using Tasks and Services 60 Advanced Java for Bioinformatics, WS 17/18, D. Huson, January 18, 2018 13 Concurrent Programming using Tasks and Services Any programs that you write will be multi-threaded. Modern computers have multiple

More information

Embedded Systems Development

Embedded Systems Development Embedded Systems Development Lecture 3 Real-Time Scheduling Dr. Daniel Kästner AbsInt Angewandte Informatik GmbH kaestner@absint.com Model-based Software Development Generator Lustre programs Esterel programs

More information

Tou has been released!

Tou has been released! Tou has been released! Shoot- em-up, heavy use of collision detection Much more open-ended than previous projects Easier than previous projects if you work smart Should help those of you combating the

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!

More information

Microcontroller VU

Microcontroller VU 182.694 Microcontroller VU Martin Perner SS 2017 Featuring Today: TinyOS Part 2 Weekly Training Objective Already done 3.4.1 Input capture 3.6.3 SPI 3.7.2 Watchdog This week 4.2.1 UART to GLCD 4.2.2 Keypad

More information

How to deal with uncertainties and dynamicity?

How to deal with uncertainties and dynamicity? How to deal with uncertainties and dynamicity? http://graal.ens-lyon.fr/ lmarchal/scheduling/ 19 novembre 2012 1/ 37 Outline 1 Sensitivity and Robustness 2 Analyzing the sensitivity : the case of Backfilling

More information

Deadlock (2) Dave Eckhardt Brian Railing Roger Dannenberg

Deadlock (2) Dave Eckhardt Brian Railing Roger Dannenberg Deadlock () Dave Eckhardt Brian Railing Roger Dannenberg 1 1-410, S'18 Synchronization P You should really have, today: Drawn pictures of thread stacks (even if not perfect) Figured out where stubs belong,

More information

Scheduling. Uwe R. Zimmer & Alistair Rendell The Australian National University

Scheduling. Uwe R. Zimmer & Alistair Rendell The Australian National University 6 Scheduling Uwe R. Zimmer & Alistair Rendell The Australian National University References for this chapter [Bacon98] J. Bacon Concurrent Systems 1998 (2nd Edition) Addison Wesley Longman Ltd, ISBN 0-201-17767-6

More information

Socket Programming. Daniel Zappala. CS 360 Internet Programming Brigham Young University

Socket Programming. Daniel Zappala. CS 360 Internet Programming Brigham Young University Socket Programming Daniel Zappala CS 360 Internet Programming Brigham Young University Sockets, Addresses, Ports Clients and Servers 3/33 clients request a service from a server using a protocol need an

More information

INF Models of concurrency

INF Models of concurrency INF4140 - Models of concurrency RPC and Rendezvous INF4140 Lecture 15. Nov. 2017 RPC and Rendezvous Outline More on asynchronous message passing interacting processes with different patterns of communication

More information

Optimal strategies for maintaining a chain of relays between an explorer and a base camp

Optimal strategies for maintaining a chain of relays between an explorer and a base camp 1/55 Optimal strategies for maintaining a chain of relays between an explorer and a base camp Lukas Humbel 2. Mai 2012 2/55 3/55 4/55 5/55 6/55 7/55 8/55 9/55 Outline 10/55 1 Model Definition Problem Statement

More information

The conceptual view. by Gerrit Muller University of Southeast Norway-NISE

The conceptual view. by Gerrit Muller University of Southeast Norway-NISE by Gerrit Muller University of Southeast Norway-NISE e-mail: gaudisite@gmail.com www.gaudisite.nl Abstract The purpose of the conceptual view is described. A number of methods or models is given to use

More information

An object-oriented design process. Weather system description. Layered architecture. Process stages. System context and models of use

An object-oriented design process. Weather system description. Layered architecture. Process stages. System context and models of use An object-oriented design process Process stages Structured design processes involve developing a number of different system models. They require a lot of effort for development and maintenance of these

More information

Chapter 7. Sequential Circuits Registers, Counters, RAM

Chapter 7. Sequential Circuits Registers, Counters, RAM Chapter 7. Sequential Circuits Registers, Counters, RAM Register - a group of binary storage elements suitable for holding binary info A group of FFs constitutes a register Commonly used as temporary storage

More information

IN4R21. Real-Time Specification for Java (RTSJ) Damien MASSON January 20, 2014

IN4R21. Real-Time Specification for Java (RTSJ) Damien MASSON  January 20, 2014 IN4R21 Real-Time Specification for Java (RTSJ) Damien MASSON http://www.esiee.fr/~massond/ January 20, 2014 References www.rtsj.org Concurrent and Real-Time Programming in Java, Andy Wellings Real-Time

More information

INF 4140: Models of Concurrency Series 3

INF 4140: Models of Concurrency Series 3 Universitetet i Oslo Institutt for Informatikk PMA Olaf Owe, Martin Steffen, Toktam Ramezani INF 4140: Models of Concurrency Høst 2016 Series 3 14. 9. 2016 Topic: Semaphores (Exercises with hints for solution)

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 12

CMSC 132, Object-Oriented Programming II Summer Lecture 12 CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 12 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 12.1 Trees

More information

COMPUTER SCIENCE TRIPOS

COMPUTER SCIENCE TRIPOS CST.2014.2.1 COMPUTER SCIENCE TRIPOS Part IA Tuesday 3 June 2014 1.30 to 4.30 pm COMPUTER SCIENCE Paper 2 Answer one question from each of Sections A, B and C, and two questions from Section D. Submit

More information

Imperative Data Parallelism (Correctness)

Imperative Data Parallelism (Correctness) Imperative Data Parallelism (Correctness) Unit 1.b 1 Acknowledgments Authored by Thomas Ball, MSR Redmond 9/4/2010 2 Concepts Code Concept Parallel.Invoke Parallel.ForEach Correctness Concept Schedules

More information

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University Basic Java OOP 10/12/2015 Hsuan-Tien Lin ( 林軒田 ) htlin@csie.ntu.edu.tw Department of Computer Science & Information Engineering National Taiwan University ( 國立台灣大學資訊工程系 ) Hsuan-Tien Lin (NTU CSIE) Basic

More information

Lecture 11 Safety, Liveness, and Regular Expression Logics

Lecture 11 Safety, Liveness, and Regular Expression Logics Lecture 11 Safety, Liveness, and Regular Expression Logics Safety and Liveness Regular Expressions w-regular Expressions Programs, Computations, and Properties Guarantee, Response, and Persistance Properties.

More information

A Spatial Data Infrastructure for Landslides and Floods in Italy

A Spatial Data Infrastructure for Landslides and Floods in Italy V Convegno Nazionale del Gruppo GIT Grottaminarda 14 16 giugno 2010 A Spatial Data Infrastructure for Landslides and Floods in Italy Ivan Marchesini, Vinicio Balducci, Gabriele Tonelli, Mauro Rossi, Fausto

More information

Administrivia. Course Objectives. Overview. Lecture Notes Week markem/cs333/ 2. Staff. 3. Prerequisites. 4. Grading. 1. Theory and application

Administrivia. Course Objectives. Overview. Lecture Notes Week markem/cs333/ 2. Staff. 3. Prerequisites. 4. Grading. 1. Theory and application Administrivia 1. markem/cs333/ 2. Staff 3. Prerequisites 4. Grading Course Objectives 1. Theory and application 2. Benefits 3. Labs TAs Overview 1. What is a computer system? CPU PC ALU System bus Memory

More information

Exercise 1 (15 points)

Exercise 1 (15 points) Exam System Validation (214012) 8:45-12:15, 25-06-2010 The exercises are worth a total of 90 points. The final grade is 10+pts 10. The exam is open book: copies of slides/papers/notes/etc. are allowed.

More information

Lab Course: distributed data analytics

Lab Course: distributed data analytics Lab Course: distributed data analytics 01. Threading and Parallelism Nghia Duong-Trung, Mohsan Jameel Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany International

More information

Distributed Architectures

Distributed Architectures Distributed Architectures Software Architecture VO/KU (707023/707024) Roman Kern KTI, TU Graz 2015-01-21 Roman Kern (KTI, TU Graz) Distributed Architectures 2015-01-21 1 / 64 Outline 1 Introduction 2 Independent

More information

Binding Performance and Power of Dense Linear Algebra Operations

Binding Performance and Power of Dense Linear Algebra Operations 10th IEEE International Symposium on Parallel and Distributed Processing with Applications Binding Performance and Power of Dense Linear Algebra Operations Maria Barreda, Manuel F. Dolz, Rafael Mayo, Enrique

More information

Simulation & Modeling Event-Oriented Simulations

Simulation & Modeling Event-Oriented Simulations Simulation & Modeling Event-Oriented Simulations Outline Simulation modeling characteristics Concept of Time A DES Simulation (Computation) DES System = model + simulation execution Data Structures Program

More information

Real-Time Scheduling. Real Time Operating Systems and Middleware. Luca Abeni

Real-Time Scheduling. Real Time Operating Systems and Middleware. Luca Abeni Real Time Operating Systems and Middleware Luca Abeni luca.abeni@unitn.it Definitions Algorithm logical procedure used to solve a problem Program formal description of an algorithm, using a programming

More information

Estimation of DNS Source and Cache Dynamics under Interval-Censored Age Sampling

Estimation of DNS Source and Cache Dynamics under Interval-Censored Age Sampling Estimation of DNS Source and Cache Dynamics under Interval-Censored Age Sampling Di Xiao, Xiaoyong Li, Daren B.H. Cline, Dmitri Loguinov Internet Research Lab Department of Computer Science and Engineering

More information

Latches. October 13, 2003 Latches 1

Latches. October 13, 2003 Latches 1 Latches The second part of CS231 focuses on sequential circuits, where we add memory to the hardware that we ve already seen. Our schedule will be very similar to before: We first show how primitive memory

More information

Modern Functional Programming and Actors With Scala and Akka

Modern Functional Programming and Actors With Scala and Akka Modern Functional Programming and Actors With Scala and Akka Aaron Kosmatin Computer Science Department San Jose State University San Jose, CA 95192 707-508-9143 akosmatin@gmail.com Abstract For many years,

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!

More information

DMP. Deterministic Shared Memory Multiprocessing. Presenter: Wu, Weiyi Yale University

DMP. Deterministic Shared Memory Multiprocessing. Presenter: Wu, Weiyi Yale University DMP Deterministic Shared Memory Multiprocessing 1 Presenter: Wu, Weiyi Yale University Outline What is determinism? How to make execution deterministic? What s the overhead of determinism? 2 What Is Determinism?

More information

Behavioral Simulations in MapReduce

Behavioral Simulations in MapReduce Behavioral Simulations in MapReduce Guozhang Wang, Marcos Vaz Salles, Benjamin Sowell, Xun Wang, Tuan Cao, Alan Demers, Johannes Gehrke, Walker White Cornell University 1 What are Behavioral Simulations?

More information

CMSC 132, Object-Oriented Programming II Summer Lecture 6:

CMSC 132, Object-Oriented Programming II Summer Lecture 6: CMSC 132, Object-Oriented Programming II Summer 2016 Lecturer: Anwar Mamat Lecture 6: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 6.1 Singly

More information

CS 425 / ECE 428 Distributed Systems Fall Indranil Gupta (Indy) Oct. 5, 2017 Lecture 12: Time and Ordering All slides IG

CS 425 / ECE 428 Distributed Systems Fall Indranil Gupta (Indy) Oct. 5, 2017 Lecture 12: Time and Ordering All slides IG CS 425 / ECE 428 Distributed Systems Fall 2017 Indranil Gupta (Indy) Oct. 5, 2017 Lecture 12: Time and Ordering All slides IG Why Synchronization? You want to catch a bus at 6.05 pm, but your watch is

More information

Real-Time and Embedded Systems (M) Lecture 5

Real-Time and Embedded Systems (M) Lecture 5 Priority-driven Scheduling of Periodic Tasks (1) Real-Time and Embedded Systems (M) Lecture 5 Lecture Outline Assumptions Fixed-priority algorithms Rate monotonic Deadline monotonic Dynamic-priority algorithms

More information

Announcements. John Jannotti (cs32) Design Patterns Feb 13, / 1

Announcements. John Jannotti (cs32) Design Patterns Feb 13, / 1 Announcements We ll code review Stars on Thursday. Volunteer your code by emailing me. Lab this week covers Ajax/Javascript. Interactive UIs. No lab (or lab hours) next week. Submit a group project idea

More information

Operating Systems. VII. Synchronization

Operating Systems. VII. Synchronization Operating Systems VII. Synchronization Ludovic Apvrille ludovic.apvrille@telecom-paristech.fr Eurecom, office 470 http://soc.eurecom.fr/os/ @OS Eurecom Outline Synchronization issues 2/22 Fall 2017 Institut

More information

Multi-threading model

Multi-threading model Multi-threading model High level model of thread processes using spawn and sync. Does not consider the underlying hardware. Algorithm Algorithm-A begin { } spawn Algorithm-B do Algorithm-B in parallel

More information

ECE 407 Computer Aided Design for Electronic Systems. Simulation. Instructor: Maria K. Michael. Overview

ECE 407 Computer Aided Design for Electronic Systems. Simulation. Instructor: Maria K. Michael. Overview 407 Computer Aided Design for Electronic Systems Simulation Instructor: Maria K. Michael Overview What is simulation? Design verification Modeling Levels Modeling circuits for simulation True-value simulation

More information

Exercise 1: Formal Tools and Techniques (10 points)

Exercise 1: Formal Tools and Techniques (10 points) EXAM System Validation (191401) 13:45-17:15 0-07-01 The exercises are worth a total of 100 points. The final grade for the course is (hw 1+hw )/+exam/10, provided that you obtain at least 50 points for

More information

Voortgezet Programmeren

Voortgezet Programmeren Voortgezet Programmeren Lecture 4: Interfaces and polymorphism Tommi Tervonen Econometric Institute, Erasmus School of Economics Rule #1: never duplicate code p u b l i c c l a s s Course { p u b l i c

More information

Concurrent HTTP Proxy Server. CS425 - Computer Networks Vaibhav Nagar(14785)

Concurrent HTTP Proxy Server. CS425 - Computer Networks Vaibhav Nagar(14785) Concurrent HTTP Proxy Server CS425 - Computer Networks Vaibhav Nagar(14785) Email: vaibhavn@iitk.ac.in August 31, 2016 Elementary features of Proxy Server Proxy server supports the GET method to serve

More information

I/O Devices. Device. Lecture Notes Week 8

I/O Devices. Device. Lecture Notes Week 8 I/O Devices CPU PC ALU System bus Memory bus Bus interface I/O bridge Main memory USB Graphics adapter I/O bus Disk other devices such as network adapters Mouse Keyboard Disk hello executable stored on

More information

B629 project - StreamIt MPI Backend. Nilesh Mahajan

B629 project - StreamIt MPI Backend. Nilesh Mahajan B629 project - StreamIt MPI Backend Nilesh Mahajan March 26, 2013 Abstract StreamIt is a language based on the dataflow model of computation. StreamIt consists of computation units called filters connected

More information

Class versus Instance (Section 5.1)

Class versus Instance (Section 5.1) Class versus Instance (Section 5.1) Hsuan-Tien Lin Department of CSIE, NTU OOP Class, March 22-23, 2010 H.-T. Lin (NTU CSIE) Class versus Instance OOP 03/22-23/2010 0 / 16 Static Variables (1/2) 1 class

More information

Discovering Spam On Twitter

Discovering Spam On Twitter Virginia Commonwealth University VCU Scholars Compass Theses and Dissertations Graduate School 2014 Discovering Spam On Twitter Ioana-Alexandra Bara Virginia Commonwealth University Follow this and additional

More information

Using Timed Input/Output Automata for Implementing Distributed Systems

Using Timed Input/Output Automata for Implementing Distributed Systems Using Timed Input/Output Automata for Implementing Distributed Systems Peter M. Musial CSAIL, MIT, MA, USA pmmusial@csail.mit.edu Abstract The objective of this work is the derivation of software that

More information