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

Size: px
Start display at page:

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

Transcription

1 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<T>, or pass the connection around. On client: Minimize redraws (not on every mouse event!). Java profiler is jvisualvm, consider YourKit. There is a JS profiler in the Chrome dev tools. John Jannotti (cs32) Design with Threads April 5, / 31

2 Design with Threads John Jannotti /course/cs0320/www/docs/lectures/ April 5, 2018 John Jannotti (cs32) Design with Threads April 5, / 31

3 A mental model for synchronized blocks 1 s y n c h r o n i z e d ( bank ) { 2 double b a l a n c e = bank. get ( John ) ; 3 b a l a n c e += ; 4 bank. put ( John, b a l a n c e ) ; 5 } becomes (CAPITALS == built in magic ) 1 LOCK l o c k = bank.getlock ( ) ; 2 t r y { 3 l o c k. OBTAIN( ) 4 double b a l a n c e = bank. get ( John ) ; 5 b a l a n c e += ; 6 bank. put ( John, b a l a n c e ) ; 7 } f i n a l l y { 8 l o c k. RELEASE ( ) ; 9 } John Jannotti (cs32) Design with Threads April 5, / 31

4 Java s synchronized methods synchronized keyword in front of method. 1 s y n c h r o n i z e d v o i d d e p o s i t ( S t r i n g name, double amount ) 2 double b a l a n c e = t a b l e. get ( name ) ; 3 b a l a n c e += amount ; 4 t a b l e. put ( name, b a l a n c e ) ; 5 } Equivalent to synchronized (this) for body. 1 v o i d d e p o s i t ( S t r i n g name, double amount ) { 2 s y n c h r o n i z e d ( t h i s ) { 3 double b a l a n c e = t a b l e. get ( name ) ; 4 b a l a n c e += amount ; 5 t a b l e. put ( name, b a l a n c e ) ; 6 } 7 } What about a static synchronized method? John Jannotti (cs32) Design with Threads April 5, / 31

5 Examples List add()/remove() in synchronized regions Can you safely do unsynchronized lookups in ArrayList? Iteration? What is the difference between Vector & ArrayList? Prefer Collections.synchronizedList(alist); Maps, Sets, and other collections Unsynchronized by default. Map sm = Collections.synchronizedMap(m); Consider java.util.concurrent.concurrent(hash)map Avoids corruption, but { get();...; put(); } still isn t atomic! John Jannotti (cs32) Design with Threads April 5, / 31

6 Dining Philosophers Five diners (threads) at round table. Need 2 forks to eat. Only 5 on table. Each picks up left (acquires lock). Then the right (acquires lock). Then eats (does work). Then puts both down (releases locks). What can go wrong? How can you ensure it won t? John Jannotti (cs32) Design with Threads April 5, / 31

7 Deadlocks Thread 1 Thread 2 Lock A Lock B Lock B... wait Lock A wait wait Doesn t just affect locks Wait for I/O from another thread/process. Trying to acquire a resource from a pool. Think about it when waiting on anything. John Jannotti (cs32) Design with Threads April 5, / 31

8 Avoiding Deadlocks (and Lock Contention) Limit the number of locks in your programs By minimizing writable sharing, not by crossing your fingers! Try to avoid the need to hold multiple locks simultaneously. If you must hold multiple locks, order them. Hold locks briefly (as measured by time and code) Keep synchronized regions short. Minimize calls inside locked regions. Avoid I/O inside locked regions. Briefly is about helping you understand your code and when locks are held, not about lower the probability of bad luck. John Jannotti (cs32) Design with Threads April 5, / 31

9 Using Threads Getting the most out of threads is tricky. Figuring out where to use threads is hard. Some things are obvious. But most potential uses aren t. Bottom line Use threads where it makes design easier, or you know you have a performance problem. Minimize (mutable) data sharing. Consider message passing designs John Jannotti (cs32) Design with Threads April 5, / 31

10 Read/Write Locks java.util.concurrent.locks.readwritelock readlock(), writelock() Multiple simultaneous readers allowed. Only one writer (with no reader) allowed. Useful for read-heavy workloads (a common situation) John Jannotti (cs32) Design with Threads April 5, / 31

11 Thread Coordination Suppose you build your KD-Tree with multiple threads. At each split, if there s enough work, fork a thread. When can you do a lookup? (That is, when are the threads done?) Can be coordinated with synchronized regions. There are more direct constructs, and you should use them. John Jannotti (cs32) Design with Threads April 5, / 31

12 Fork/Join Basic operations for run-to-completion threads. Fork: create and start a new thread Join: wait for a thread to exit Structured in some languages Fork/join are visible in the lexical structure of the program. A forked section might look like a special block. Java is unstructured Fork: Thread t = new Thread(work); t.start() Join: t.join() or t.join(timeout) How would you join multiple threads? PS. Java 7 introduced a Fork/Join Framework that you might consider. John Jannotti (cs32) Design with Threads April 5, / 31

13 Monitors Used when conditions control access, not just mutual exclusion. We ll describe what the Java language provides. But also be aware of what the standard libraries offer. java.util.concurrent com.google.common.util.concurrent Java provides basic control primitives Waiting (for condition to hold) Notifying (of change in condition) Java does not provide the parenthetical semantics on these operations. John Jannotti (cs32) Design with Threads April 5, / 31

14 Wait-Notify A thread wants to yield CPU until an event occurs Coordination without termination (unlike join()) Wait for another thread to provide needed data. Wait for user to push a button. Java provides this in a limited way. Event must be explicitly noticed by another thread. That other thread needs to tell the waiting thread about it. Java Implementation Wait by calling o.wait() or o.wait(timeout) Another thread must call o.notifyall() (on the same object). Or o.notify() (in any doubt? use notifyall) stackoverflow.com/questions/37026/java-notify-vs-notifyall-all-overagain John Jannotti (cs32) Design with Threads April 5, / 31

15 Wait-Notify to implement a Monitor Details are slightly tricky Java allows wait() on an object, not a condition obj.wait() must occur while synchronized on obj. Notify must occur on the same object. And also while synchronized by that object. Simplified code pattern 1 s y n c h r o n i z e d ( o b j ) { 2 w h i l e (! c o n d i t i o n ) { 3 o b j. w a i t ( ) ; 4 } 5 } John Jannotti (cs32) Design with Threads April 5, / 31

16 Producer-Consumer Consumer Gets next item from queue. Processes that item. 1 w h i l e ( t r u e ) { 2 s y n c h r o n i z e d ( queue ) { 3 w h i l e ( queue. isempty ( ) ) { 4 t r y { 5 queue. w a i t ( ) ; 6 } 7 c atch ( I n t e r r u p t e d E x c e p t i o n e ) { } 8 } 9 next = queue. remove ( ) ; 0 } 1 next. p r o c e s s ( ) ; 2 } John Jannotti (cs32) Design with Threads April 5, / 31

17 Producer-Consumer Producer Adds items to queue 1 w h i l e ( t r u e ) { 2 item = <get next item> 3 s y n c h r o n i z e d ( queue ) { 4 queue. add ( item ) ; 5 queue. n o t i f y ( ) ; 6 } 7 } John Jannotti (cs32) Design with Threads April 5, / 31

18 Building up from Primitives Now you know all the primitives you need. But actually, you should rarely use them! Get to know the java.util.concurrent package. Executors more flexible than raw Threads Concurrent Data Structures A variety of lock types / synchronization Written by smart, focused people. We ll motivate some of these utilities and implement some (perhaps poorly) so you never should! John Jannotti (cs32) Design with Threads April 5, / 31

19 Raw threads can be inflexible Consider a Web Server or Ray Tracing Engine. Both are embarassingly parallel Just start one thread per client connection! Just break the image into tiles! And yet... Too many clients... nobody served. How many tiles? John Jannotti (cs32) Design with Threads April 5, / 31

20 Separate specification of work from thread management You already wrote your code as Runnables. Instead of (new Thread(r)).start(); Generalize with an Executor. 1 E x e c u t o r e = <Get E x e c u t o r Implementation >; 2 e. e x e c u t e ( r ) ; Allows flexible execution. Serial, Pools, Scheduled... How would you implement a ThreadPoolExecutor? What does ThreadPoolExecutor.execute(Runnable) do? What will be shared among threads, and how will you protect it? John Jannotti (cs32) Design with Threads April 5, / 31

21 WorkerThread run() 1 p u b l i c v o i d run ( ) { 2 w h i l e ( t r u e ) { 3 Runnable t a s k = n u l l ; 4 s y n c h r o n i z e d ( work queue ) { 5 w h i l e ( work queue. isempty ( ) ) { 6 t r y { 7 work queue. w a i t ( ) ; 8 } c atch ( I n t e r r u p t e d E x c e p t i o n e ) { } 9 } 0 t a s k = work queue. remove ( ) ; 1 } 2 t a s k. run ( ) ; / Why not two l i n e s up? / 3 } 4 } John Jannotti (cs32) Design with Threads April 5, / 31

22 Handling Errors What if the internal run() throws an exception? Do you want to stop the worker? Do you want to record the report/problem? 1 t r y { 2 t a s k. run ( ) ; 3 } c a t c h ( Throwable t ) { 4 // l o g an e r r o r ( and s t a c k t r a c e?) 5 } Be sure to catch Throwable. Runnable doesn t support returning values (or errors). John Jannotti (cs32) Design with Threads April 5, / 31

23 Adding to the queue() 1 p u b l i c v o i d e x e c u t e ( Runnable t a s k ) { 2 s y n c h r o n i z e d ( work queue ) { 3 work queue. add ( t a s k ) ; 4 work queue. n o t i f y A l l ( ) ; 5 } 6 } Together, these are the Monitor code pattern. Specifically Producer/Consumer. John Jannotti (cs32) Design with Threads April 5, / 31

24 Producer/Consumer The monitor code fragment is not very clear. A BlockingQueue is a nicer abstraction. 1 p u b l i c v o i d run ( ) { 2 w h i l e ( t r u e ) { 3 t r y { 4 Runnable t a s k = work queue. t a k e ( ) ; 5 t a s k. run ( ) ; / No w o r r i e s about b e i n g slow. / 6 } c a tch ( I n t e r r u p t e d E x c e p t i o n e ) { } 7 } 8 } 9 p u b l i c v o i d e x e c u t e ( Runnable t a s k ) { 0 t r y { 1 work queue. put ( t a s k ) ; 2 } c atch ( I n t e r r u p t e d E x c e p t i o n e ) { } 3 } John Jannotti (cs32) Design with Threads April 5, / 31

25 Task completion and returning values There s no longer a Thread to join(). How can we tell if our tasks are complete? Do you care about individual tasks? Or maybe just that all of them are done. Ideas? John Jannotti (cs32) Design with Threads April 5, / 31

26 Several designs Query the queue size (all). Only if you know all tasks submitted. Queue would need to lie about the currently running task. Use a CountDownLatch (n). Provide a better Runnable implementation that wraps Runnables. Make a class that knows it has been run. void execute(donerunnable task) task.isdone() JDK: void execute(runnablefuture<t> task) Use a richer execute() interface. Future<T> submit(callable<t> task) Future and Callable are real. Speculate on their interface? Available from an ExecutorService John Jannotti (cs32) Design with Threads April 5, / 31

27 Concurrent Datastructures Suppose you want to use a Map or Queue in several threads. You could use Collections.synchronizedMap (et al.) But Those make every method synchronized And still require external synchronization for common ops. 1 s y n c h r o n i z e d (map) { 2 i f (! map. c o n t a i n s K e y ( key ) ) 3 v a l u e = <some l e n g t h y computation >; 4 r e t u r n map. put ( key, v a l u e ) ; 5 e l s e 6 r e t u r n map. get ( key ) ; 7 } ConcurrentHashMap offers putifabsent and even computeifabsent. John Jannotti (cs32) Design with Threads April 5, / 31

28 Concurrency utilities to the rescue ConcurrentMap, ConcurrentQueue interfaces. ConcurrentHashMap, ConcurrentLinkedQueue... classes. Allow multiple readers (and sometimes writers) oldval = map.putifabsent(key, value); newval = map.computeifabsent(key, Tile::new) John Jannotti (cs32) Design with Threads April 5, / 31

29 Simple atomic ooperations A common shared variable is a statistics counter. Multiple threads need to increment atomically. java.util.concurrent.atomic.atomicinteger John Jannotti (cs32) Design with Threads April 5, / 31

30 Immutable Objects Consider a Complex number package. 1 p u b l i c v o i d add ( o t h e r ) { 2 r e a l += o t h e r. r e a l ; 3 imag += o t h e r. imag ; 4 } vs 1 p u b l i c Complex add ( Complex o t h e r ) { 2 r e t u r n new Complex ( r e a l + o t h e r. r e a l, 3 imag + o t h e r. imag ) ; 4 } John Jannotti (cs32) Design with Threads April 5, / 31

31 Synchronization and Files Files are not inherently thread-safe. I/O may not be atomic. POSIX specifies some guarantees, but libraries obfuscate details. And file position is shared across threads Try to access files with only one thread Or use synchronization (on the same object!) Not like this: synchronized (new File("safe.txt")) {... } Don t worry about pure-read workloads. Log files are problematic (maybe you don t mind). OS supports opening in append mode. new FileWriter(..., true) John Jannotti (cs32) Design with Threads April 5, / 31

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

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

Improper Nesting Example

Improper Nesting Example Improper Nesting Example One of the limits on the use of parbegin/parend, and any related constructs, is that the program involved must be properly nested. Not all programs are. For example, consider the

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

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

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

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

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

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

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

Course Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1

Course Announcements. John Jannotti (cs32) Scope, Collections & Generics Feb 8, / 1 Course Announcements Stars is due tomorrow. Stars grades should be out by next Monday. Javascript lab out today. How you make interactive webby GUIs. Today we re going to cover a bit of a hodge podge.

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

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

MURA Office hours Thurs at 12-1pm in CIT 546 Contact for more info.

MURA Office hours Thurs at 12-1pm in CIT 546 Contact for more info. Course Announcements Lecture capture has begun, available from Lectures page. First two and a half weeks are packed. Testing lab done, HTML started, and Stars due next Friday. Department has a lot of student

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

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

Course Announcements. Bacon is due next Monday. Next lab is about drawing UIs. Today s lecture will help thinking about your DB interface.

Course Announcements. Bacon is due next Monday. Next lab is about drawing UIs. Today s lecture will help thinking about your DB interface. Course Announcements Bacon is due next Monday. Today s lecture will help thinking about your DB interface. Next lab is about drawing UIs. John Jannotti (cs32) ORMs Mar 9, 2017 1 / 24 ORMs John Jannotti

More information

Design Patterns and Refactoring

Design Patterns and Refactoring Singleton Oliver Haase HTWG Konstanz 1 / 19 Description I Classification: object based creational pattern Puropse: ensure that a class can be instantiated exactly once provide global access point to single

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

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

Disproof in Jape (a short how-to note)

Disproof in Jape (a short how-to note) Disproof in Jape (a short how-to note) Richard Bornat (richard@bornat.me.uk) December 15, 2003 The examples/natural deduction/i2l.jt encoding of natural deduction in Jape allows for disproof as well as

More information

Algorithmic verification

Algorithmic verification Algorithmic verification Ahmed Rezine IDA, Linköpings Universitet Hösttermin 2018 Outline Overview Model checking Symbolic execution Outline Overview Model checking Symbolic execution Program verification

More information

UI Implementation. John Jannotti. Mar 21, /course/cs0320/www/docs/lectures/ John Jannotti (cs32) UI Implementation Mar 21, / 26

UI Implementation. John Jannotti. Mar 21, /course/cs0320/www/docs/lectures/ John Jannotti (cs32) UI Implementation Mar 21, / 26 UI Implementation John Jannotti /course/cs0320/www/docs/lectures/ Mar 21, 2017 John Jannotti (cs32) UI Implementation Mar 21, 2017 1 / 26 Announcements If you won t see/work with your partner over Spring

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

A Series Transformations

A Series Transformations .3 Constructing Rotations We re halfway through the transformations and our next one, the rotation, gives a congruent image just like the reflection did. Just remember that a series of transformations

More information

Discrete Structures Proofwriting Checklist

Discrete Structures Proofwriting Checklist CS103 Winter 2019 Discrete Structures Proofwriting Checklist Cynthia Lee Keith Schwarz Now that we re transitioning to writing proofs about discrete structures like binary relations, functions, and graphs,

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

Correctness of Concurrent Programs

Correctness of Concurrent Programs Correctness of Concurrent Programs Trifon Ruskov ruskov@tu-varna.acad.bg Technical University of Varna - Bulgaria Correctness of Concurrent Programs Correctness of concurrent programs needs to be formalized:

More information

Deadlock. CSE 2431: Introduction to Operating Systems Reading: Chap. 7, [OSC]

Deadlock. CSE 2431: Introduction to Operating Systems Reading: Chap. 7, [OSC] Deadlock CSE 2431: Introduction to Operating Systems Reading: Chap. 7, [OSC] 1 Outline Resources Deadlock Deadlock Prevention Deadlock Avoidance Deadlock Detection Deadlock Recovery 2 Review: Synchronization

More information

Quadratic Equations Part I

Quadratic Equations Part I Quadratic Equations Part I Before proceeding with this section we should note that the topic of solving quadratic equations will be covered in two sections. This is done for the benefit of those viewing

More information

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

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ; 1 Trees The next major set of data structures belongs to what s called Trees. They are called that, because if you try to visualize the structure, it kind of looks like a tree (root, branches, and leafs).

More information

Comprehensive support for quantitation

Comprehensive support for quantitation Comprehensive support for quantitation One of the major new features in the current release of Mascot is support for quantitation. This is still work in progress. Our goal is to support all of the popular

More information

CIS 4930/6930: Principles of Cyber-Physical Systems

CIS 4930/6930: Principles of Cyber-Physical Systems CIS 4930/6930: Principles of Cyber-Physical Systems Chapter 11 Scheduling Hao Zheng Department of Computer Science and Engineering University of South Florida H. Zheng (CSE USF) CIS 4930/6930: Principles

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

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

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

Threadsafe design Confinement (revisited) Java monitor pattern. Delegating thread safety. Untitled Sheets HOM. Threadsafe design

Threadsafe design Confinement (revisited) Java monitor pattern. Delegating thread safety. Untitled Sheets HOM. Threadsafe design /FHTenL February 22, 2017 1/30 The design process for a threadsafe class should include three basic elements: Identify the variables (members) that form the object s state; Identify the invariants that

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

Hypothesis testing I. - In particular, we are talking about statistical hypotheses. [get everyone s finger length!] n =

Hypothesis testing I. - In particular, we are talking about statistical hypotheses. [get everyone s finger length!] n = Hypothesis testing I I. What is hypothesis testing? [Note we re temporarily bouncing around in the book a lot! Things will settle down again in a week or so] - Exactly what it says. We develop a hypothesis,

More information

PHP-Einführung - Lesson 4 - Object Oriented Programming. Alexander Lichter June 27, 2017

PHP-Einführung - Lesson 4 - Object Oriented Programming. Alexander Lichter June 27, 2017 PHP-Einführung - Lesson 4 - Object Oriented Programming Alexander Lichter June 27, 2017 Content of this lesson 1. Recap 2. Why OOP? 3. Git gud - PHPStorm 4. Include and Require 5. Classes and objects 6.

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

INF Models of concurrency

INF Models of concurrency Monitors INF4140 - Models of concurrency Monitors, lecture 4 Fall 2017 27. September 2017 2 / 49 Overview Concurrent execution of different processes Communication by shared variables Processes may interfere

More information

CS 453 Operating Systems. Lecture 7 : Deadlock

CS 453 Operating Systems. Lecture 7 : Deadlock CS 453 Operating Systems Lecture 7 : Deadlock 1 What is Deadlock? Every New Yorker knows what a gridlock alert is - it s one of those days when there is so much traffic that nobody can move. Everything

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

A subtle problem. An obvious problem. An obvious problem. An obvious problem. No!

A subtle problem. An obvious problem. An obvious problem. An obvious problem. No! A subtle problem An obvious problem when LC = t do S doesn t make sense for Lamport clocks! there is no guarantee that LC will ever be S is anyway executed after LC = t Fixes: if e is internal/send and

More information

What happens to the value of the expression x + y every time we execute this loop? while x>0 do ( y := y+z ; x := x:= x z )

What happens to the value of the expression x + y every time we execute this loop? while x>0 do ( y := y+z ; x := x:= x z ) Starter Questions Feel free to discuss these with your neighbour: Consider two states s 1 and s 2 such that s 1, x := x + 1 s 2 If predicate P (x = y + 1) is true for s 2 then what does that tell us about

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

HOLLOMAN S AP STATISTICS BVD CHAPTER 08, PAGE 1 OF 11. Figure 1 - Variation in the Response Variable

HOLLOMAN S AP STATISTICS BVD CHAPTER 08, PAGE 1 OF 11. Figure 1 - Variation in the Response Variable Chapter 08: Linear Regression There are lots of ways to model the relationships between variables. It is important that you not think that what we do is the way. There are many paths to the summit We are

More information

Cuts. Cuts. Consistent cuts and consistent global states. Global states and cuts. A cut C is a subset of the global history of H

Cuts. Cuts. Consistent cuts and consistent global states. Global states and cuts. A cut C is a subset of the global history of H Cuts Cuts A cut C is a subset of the global history of H C = h c 1 1 hc 2 2...hc n n A cut C is a subset of the global history of H The frontier of C is the set of events e c 1 1,ec 2 2,...ec n n C = h

More information

Distributed Systems Principles and Paradigms

Distributed Systems Principles and Paradigms Distributed Systems Principles and Paradigms Chapter 6 (version April 7, 28) Maarten van Steen Vrije Universiteit Amsterdam, Faculty of Science Dept. Mathematics and Computer Science Room R4.2. Tel: (2)

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

Math101, Sections 2 and 3, Spring 2008 Review Sheet for Exam #2:

Math101, Sections 2 and 3, Spring 2008 Review Sheet for Exam #2: Math101, Sections 2 and 3, Spring 2008 Review Sheet for Exam #2: 03 17 08 3 All about lines 3.1 The Rectangular Coordinate System Know how to plot points in the rectangular coordinate system. Know the

More information

CS5412: REPLICATION, CONSISTENCY AND CLOCKS

CS5412: REPLICATION, CONSISTENCY AND CLOCKS 1 CS5412: REPLICATION, CONSISTENCY AND CLOCKS Lecture X Ken Birman Recall that clouds have tiers 2 Up to now our focus has been on client systems and the network, and the way that the cloud has reshaped

More information

CS-206 Concurrency. Lecture 13. Wrap Up. Spring 2015 Prof. Babak Falsafi parsa.epfl.ch/courses/cs206/

CS-206 Concurrency. Lecture 13. Wrap Up. Spring 2015 Prof. Babak Falsafi parsa.epfl.ch/courses/cs206/ CS-206 Concurrency Lecture 13 Wrap Up Spring 2015 Prof. Babak Falsafi parsa.epfl.ch/courses/cs206/ Created by Nooshin Mirzadeh, Georgios Psaropoulos and Babak Falsafi EPFL Copyright 2015 EPFL CS-206 Spring

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

1 Introduction. 1.1 The Problem Domain. Self-Stablization UC Davis Earl Barr. Lecture 1 Introduction Winter 2007

1 Introduction. 1.1 The Problem Domain. Self-Stablization UC Davis Earl Barr. Lecture 1 Introduction Winter 2007 Lecture 1 Introduction 1 Introduction 1.1 The Problem Domain Today, we are going to ask whether a system can recover from perturbation. Consider a children s top: If it is perfectly vertically, you can

More information

Cosmic Ray Detector Software

Cosmic Ray Detector Software Cosmic Ray Detector Software Studying cosmic rays has never been easier Matthew Jones Purdue University 2012 QuarkNet Summer Workshop 1 Brief History First cosmic ray detector built at Purdue in about

More information

Reading and Writing. Mathematical Proofs. Slides by Arthur van Goetham

Reading and Writing. Mathematical Proofs. Slides by Arthur van Goetham Reading and Writing Mathematical Proofs Slides by Arthur van Goetham What is a proof? Why explanations are not proofs What is a proof? A method for establishing truth What establishes truth depends on

More information

Propositions. c D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 5.1, Page 1

Propositions. c D. Poole and A. Mackworth 2010 Artificial Intelligence, Lecture 5.1, Page 1 Propositions An interpretation is an assignment of values to all variables. A model is an interpretation that satisfies the constraints. Often we don t want to just find a model, but want to know what

More information

Where on Earth are We? Projections and Coordinate Reference Systems

Where on Earth are We? Projections and Coordinate Reference Systems Where on Earth are We? Projections and Coordinate Reference Systems Nick Eubank February 11, 2018 If I told you that there was a treasure chest buried at the coordinates p2, 5q, your first response might

More information

Solution to Proof Questions from September 1st

Solution to Proof Questions from September 1st Solution to Proof Questions from September 1st Olena Bormashenko September 4, 2011 What is a proof? A proof is an airtight logical argument that proves a certain statement in general. In a sense, it s

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

PHYSICS 15a, Fall 2006 SPEED OF SOUND LAB Due: Tuesday, November 14

PHYSICS 15a, Fall 2006 SPEED OF SOUND LAB Due: Tuesday, November 14 PHYSICS 15a, Fall 2006 SPEED OF SOUND LAB Due: Tuesday, November 14 GENERAL INFO The goal of this lab is to determine the speed of sound in air, by making measurements and taking into consideration the

More information

One sided tests. An example of a two sided alternative is what we ve been using for our two sample tests:

One sided tests. An example of a two sided alternative is what we ve been using for our two sample tests: One sided tests So far all of our tests have been two sided. While this may be a bit easier to understand, this is often not the best way to do a hypothesis test. One simple thing that we can do to get

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

Park School Mathematics Curriculum Book 9, Lesson 2: Introduction to Logarithms

Park School Mathematics Curriculum Book 9, Lesson 2: Introduction to Logarithms Park School Mathematics Curriculum Book 9, Lesson : Introduction to Logarithms We re providing this lesson as a sample of the curriculum we use at the Park School of Baltimore in grades 9-11. If you d

More information

Distributed Systems Principles and Paradigms. Chapter 06: Synchronization

Distributed Systems Principles and Paradigms. Chapter 06: Synchronization Distributed Systems Principles and Paradigms Maarten van Steen VU Amsterdam, Dept. Computer Science Room R4.20, steen@cs.vu.nl Chapter 06: Synchronization Version: November 16, 2009 2 / 39 Contents Chapter

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

Spectral Analysis of High Resolution X-ray Binary Data

Spectral Analysis of High Resolution X-ray Binary Data Spectral Analysis of High Resolution X-ray Binary Data Michael Nowak, mnowak@space.mit.edu X-ray Astronomy School; Aug. 1-5, 2011 Introduction This exercise takes a look at X-ray binary observations using

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

appstats27.notebook April 06, 2017

appstats27.notebook April 06, 2017 Chapter 27 Objective Students will conduct inference on regression and analyze data to write a conclusion. Inferences for Regression An Example: Body Fat and Waist Size pg 634 Our chapter example revolves

More information

Methods for the specification and verification of business processes MPB (6 cfu, 295AA)

Methods for the specification and verification of business processes MPB (6 cfu, 295AA) Methods for the specification and verification of business processes MPB (6 cfu, 295AA) Roberto Bruni http://www.di.unipi.it/~bruni 08 - Petri nets basics 1 Object Formalization of the basic concepts of

More information

Warm-up Using the given data Create a scatterplot Find the regression line

Warm-up Using the given data Create a scatterplot Find the regression line Time at the lunch table Caloric intake 21.4 472 30.8 498 37.7 335 32.8 423 39.5 437 22.8 508 34.1 431 33.9 479 43.8 454 42.4 450 43.1 410 29.2 504 31.3 437 28.6 489 32.9 436 30.6 480 35.1 439 33.0 444

More information

P vs. NP. Data Structures and Algorithms CSE AU 1

P vs. NP. Data Structures and Algorithms CSE AU 1 P vs. NP Data Structures and Algorithms CSE 373-18AU 1 Goals for today Define P, NP, and NP-complete Explain the P vs. NP problem -why it s the biggest open problem in CS. -And what to do when a problem

More information

Nondeterministic finite automata

Nondeterministic finite automata Lecture 3 Nondeterministic finite automata This lecture is focused on the nondeterministic finite automata (NFA) model and its relationship to the DFA model. Nondeterminism is an important concept in the

More information

Getting Started with Communications Engineering

Getting Started with Communications Engineering 1 Linear algebra is the algebra of linear equations: the term linear being used in the same sense as in linear functions, such as: which is the equation of a straight line. y ax c (0.1) Of course, if we

More information

Java Programming. Final Examination on December 13, 2015 Fall 2015

Java Programming. Final Examination on December 13, 2015 Fall 2015 Java Programming Final Examination on December 13, 2015 Fall 2015 Department of Computer Science and Information Engineering National Taiwan University Problem 1 (10 points) Multiple choice questions.

More information

Lecture 27: Theory of Computation. Marvin Zhang 08/08/2016

Lecture 27: Theory of Computation. Marvin Zhang 08/08/2016 Lecture 27: Theory of Computation Marvin Zhang 08/08/2016 Announcements Roadmap Introduction Functions Data Mutability Objects This week (Applications), the goals are: To go beyond CS 61A and see examples

More information

Uncertainty. Michael Peters December 27, 2013

Uncertainty. Michael Peters December 27, 2013 Uncertainty Michael Peters December 27, 20 Lotteries In many problems in economics, people are forced to make decisions without knowing exactly what the consequences will be. For example, when you buy

More information

Visualizing Big Data on Maps: Emerging Tools and Techniques. Ilir Bejleri, Sanjay Ranka

Visualizing Big Data on Maps: Emerging Tools and Techniques. Ilir Bejleri, Sanjay Ranka Visualizing Big Data on Maps: Emerging Tools and Techniques Ilir Bejleri, Sanjay Ranka Topics Web GIS Visualization Big Data GIS Performance Maps in Data Visualization Platforms Next: Web GIS Visualization

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

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

Scalability is Quantifiable

Scalability is Quantifiable Scalability is Quantifiable Universal Scalability Law Baron Schwartz - November 2017 Logistics & Stuff Slides will be posted :) Ask questions anytime! Founder of VividCortex Wrote High Performance MySQL

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

Intermediate Logic. Natural Deduction for TFL

Intermediate Logic. Natural Deduction for TFL Intermediate Logic Lecture Two Natural Deduction for TFL Rob Trueman rob.trueman@york.ac.uk University of York The Trouble with Truth Tables Natural Deduction for TFL The Trouble with Truth Tables The

More information

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 07/2014 SESSION 8:00-10:00

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 07/2014 SESSION 8:00-10:00 FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CAMPUS CSC2A10 OBJECT ORIENTED PROGRAMMING AUCKLAND PARK CAMPUS (APK) EXAM JULY 2014 DATE 07/2014 SESSION 8:00-10:00 ASSESOR(S)

More information

Part I. System call overview. Secure Operating System Design and Implementation System Calls. Overview. Abstraction. Jon A. Solworth.

Part I. System call overview. Secure Operating System Design and Implementation System Calls. Overview. Abstraction. Jon A. Solworth. Secure Operating System Design and Implementation System Calls Jon A. Solworth Part I System call overview Dept. of Computer Science University of Illinois at Chicago February 1, 2011 Overview Abstraction

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

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2019 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

Object Modeling Approach! Object Modeling Approach!

Object Modeling Approach! Object Modeling Approach! Object Modeling Approach! 1 Object Modeling Approach! Start with a problem statement! High-level requirements! Define object model! Identify objects and classes! Prepare data dictionary! Identify associations

More information

Sequential Logic (3.1 and is a long difficult section you really should read!)

Sequential Logic (3.1 and is a long difficult section you really should read!) EECS 270, Fall 2014, Lecture 6 Page 1 of 8 Sequential Logic (3.1 and 3.2. 3.2 is a long difficult section you really should read!) One thing we have carefully avoided so far is feedback all of our signals

More information

Calculus II. Calculus II tends to be a very difficult course for many students. There are many reasons for this.

Calculus II. Calculus II tends to be a very difficult course for many students. There are many reasons for this. Preface Here are my online notes for my Calculus II course that I teach here at Lamar University. Despite the fact that these are my class notes they should be accessible to anyone wanting to learn Calculus

More information

Lecture 4: Process Management

Lecture 4: Process Management Lecture 4: Process Management Process Revisited 1. What do we know so far about Linux on X-86? X-86 architecture supports both segmentation and paging. 48-bit logical address goes through the segmentation

More information

Lecture 16 More Profiling: gperftools, systemwide tools: oprofile, perf, DTrace, etc.

Lecture 16 More Profiling: gperftools, systemwide tools: oprofile, perf, DTrace, etc. Lecture 16 More Profiling: gperftools, systemwide tools: oprofile, perf, DTrace, etc. ECE 459: Programming for Performance March 6, 2014 Part I gperftools 2 / 49 Introduction to gperftools Google Performance

More information

Usability Extensions for the Worklet Service

Usability Extensions for the Worklet Service Usability Extensions for the Worklet Service Michael Adams Queensland University of Technology, Brisbane, Australia. mj.adams@qut.edu.au Abstract. The YAWL Worklet Service is an effective approach to facilitating

More information

rethinking software design by analyzing state

rethinking software design by analyzing state rethinking software design state by analyzing Daniel Jackson Workshop Honoring Shmuel Katz Technion Dec 19, 2013 three puzzles three puzzles why are formal methods not widely used? great advances, successful

More information

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Digital Logic

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Digital Logic Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: Digital Logic Our goal for the next few weeks is to paint a a reasonably complete picture of how we can go from transistor

More information

Physics E-1ax, Fall 2014 Experiment 3. Experiment 3: Force. 2. Find your center of mass by balancing yourself on two force plates.

Physics E-1ax, Fall 2014 Experiment 3. Experiment 3: Force. 2. Find your center of mass by balancing yourself on two force plates. Learning Goals Experiment 3: Force After you finish this lab, you will be able to: 1. Use Logger Pro to analyze video and calculate position, velocity, and acceleration. 2. Find your center of mass by

More information

CHAPTER 7: TECHNIQUES OF INTEGRATION

CHAPTER 7: TECHNIQUES OF INTEGRATION CHAPTER 7: TECHNIQUES OF INTEGRATION DAVID GLICKENSTEIN. Introduction This semester we will be looking deep into the recesses of calculus. Some of the main topics will be: Integration: we will learn how

More information