Thread states. Java threads: synchronization. Thread states (cont.)

Size: px
Start display at page:

Download "Thread states. Java threads: synchronization. Thread states (cont.)"

Transcription

1 Thread states Java threads: synchronization 1. New: created with the new operator (not yet started) 2. Runnable: either running or ready to run 3. Blocked: deactivated to wait for something 4. Dead: has executed its run method to completion, or terminated by an uncaught exception a started thread is executed in its own run-time context consisting of: program counter, call stack, and some working memory (registers, cache) 1 2 Thread states Thread states (cont.) don't confuse the interface java.lang.runnable with the state Runnable "running" is not a separate state within Runnable, but Thread.currentThread () // static method identifies the current thread object (for itself) thread.isalive () tells if the thread has been started (is not New) and not yet Dead you cannot directly ask whether an alive thread is Runnable or Blocked you cannot directly ask whether a non-alive thread is still New or already Dead 3 4 1

2 Entering the Blocked state A thread enters the blocked state when: 1. the thread goes to sleep by calling the sleep method 2. the thread calls an operation that blocks until IO operations are complete 3. the thread tries to acquire a lock that is currently held by another thread (mutual exclusion) 4. the thread waits for a condition 5 Transition from Blocked to Runnable A blocked thread moves into the Runnable state when 1. if in sleep, the specified number of milliseconds have been expired 2. if waiting for the completion of an IO operation, the IO operation have finished 3. if waiting for a lock that was owned by another thread, the other thread have released its ownership of the lock 4. if waits for a condition, another thread signals that the condition (may) have changed additionally, can wait for a lock or a condition with a timeout 6 Java Memory Model computers can temporarily hold memory values in registers or local memory caches, and the compiler can reorder instructions to optimize throughput without synchronization, threads (interleaved or parallel) may see out-of-date and/or out-of-order values for the same memory locations locks always ensure that all calculated results are visible to other threads (flushing of caches, etc.) alternatively, you can declare a flag field as volatile: private volatile boolean done;.. public boolean isdone () { return done; a write to a volatile variable synchronizes with all subsequent reads of that same variable (all reads and writes are atomic, even for long and double) 7 Mutual exclusion from critical code basic way to protecting a shared code block: mylock.lock (); // a ReentrantLock object critical section finally { mylock.unlock (); only one thread at a time can enter the critical section (identified and protected by this particular lock) any other threads calling on this lock, are blocked until the first thread unlocks the finally clause makes sure the lock is unlocked even if an exception is thrown 8 2

3 Fairness you can specify that you want a fair locking policy: Lock fairlock = new ReentrantLock (true); a fair lock favors the thread that has been waiting for the longest time by default, locks are not required to be fair for implementation reasons fair locks can be much slower than regular locks anyway, you have no guarantee that the thread scheduler provided by the plarform is fair so if the thread scheduler neglects a thread, it may not get the chance to be treated fairly by the lock 9 Condition objects a lock protects sections of code, allowing only one thread to execute the code at a time a lock manages threads that are trying to enter a protected code segment a lock can have one or more associated condition objects each condition object manages threads that have entered a protected code section but that cannot proceed for some reason (usually, lack of data / resource) 10 Condition objects (cont.) use a condition object to manage threads that have acquired a lock but cannot proceed with useful work Condition cond = lock.newcondition ();.. lock.lock (); while (!(ok to proceed)) // try until succeeds cond.await (); // data available: do something useful finally { lock.unlock (); must itself check that the condition is (still) valid 11 Condition objects (cont.) some other thread must call the signalall method to wake up any waiting threads change some item used in condition test.. cond.signalall (); // or rarely: signal () the condition wait must always be done in a loop while (! condition) cond.await (); multiple threads may compete to acquire the lock the first one can use up resources, and so others must then enter back to the blocked state to wait additionally, a "spurious wakeup" (without signal) is permitted to occur (depending on the OS) 12 3

4 Keyword "synchronized" since version 1.0, every object has an implicit lock to be used in so-called monitor methods: public synchronized void method () { body this is the equivalent of the following pseudocode: public void method () { // use explicit lock this.implicitlock.lock (); // pseudocode body finally { this.implicitlock.unlock(); Keyword synchronized (cont.) the monitor lock also has a single implicit associated condition with the following operations wait adds a thread to its set of waiting threads notifyall unblocks all waiting threads to compete for access these correspond to the following lock calls implicitcondition.await (); // pseudocode implicitcondition.signalall (); the wait and notifyall methods are final methods in Object so the Condition methods had to be renamed differently: await and signalall Synchronized code blocks an implicit lock can be acquired also by entering a code block synchronized by an object lock: synchronized (obj) { critical section // any object // implicit lock and unlock the lock is reentrant: if a thread has acquired the lock, it can acquire it again (increments a count) similarly, a monitor method can call other monitor methods with the same implicit lock without waiting you can declare a static monitor method: it uses the the associated class object ("X.class") as its lock Limitations of implicit locks and conditions you cannot interrupt a thread that is waiting to acquire a lock you cannot specify a timeout when trying to acquire a lock having only one single condition per lock can be inefficient cannot separate buffer empty (cannot take) vs. buffer full (cannot put) conditions the virtual machine locking primitives do not map well to the most efficient locking mechanisms available in modern hardware

5 Lock testing and timeouts can be cautious about acquiring a lock: if (mylock.trylock ()) { // now the thread owns the lock do something finally { mylock.unlock (); else { do something else can call trylock with a timeout parameter: if (mylock.trylock(10,timeunit.milliseconds))... TimeUnit can be: SECONDS, MILLISECONDS, MICROSECONDS, or NANOSECONDS. 17 Lock testing and timeouts (cont.) if you call trylock with a timeout, then it can throw InterruptedException when interrupted can try to break up deadlocks and such the lockinterruptibly method has the same meaning as trylock with an infinite timeout can also supply a timeout for a condition wait; mycondition.await (10, TimeUnit.MILLISECONDS)); returns if another thread has called signalall - or if the given timeout has elapsed await methods throw an InterruptedException if the thread is interrupted (but awaituninterruptibly) 18 Summary of synchronization operations synchronized (lock) {.. use shared data synchronized void method () {.. use shared data lock.lock () {.. finally { lock.unlock (); // explicit waiting for a condition to proceed:.. while (!(cannot proceed)) wait ();.. // means: this.wait (); catch (InterruptedException e) {.. either anyobject.wait (); or condition.await (); either anyobject.notifyall (); or condition.signalall (); 19 Recommendations 1. it is best to use neither lock/condition nor the old monitor methods/code blocks ("synchronized") in many situations, better to use mechanisms of the java.util.concurrent package that do all the locking and synchronization for you for example, a blocking queue can synchronize threads that work on a common pipeline 2. if the monitor methods work for your situation, prefer using them: less code to write and so less room for error 3. use explicit locks/conditions only if you need the additional power of these constructs 20 5

6 java.util.concurrent: thread management tools ReentrantReadWriteLock provides shared access for readers, and exclusive access for a writer BlockingQueue <E> can cause a thread to block when trying to add to a full queue or trying to remove from empty one ConcurrentLinkedQueue <E> and ArrayBlockingQueue <E> provide optionally-bounded/bounded thread-safe queues interface ConcurrentMap <K,V> implemented efficiently by ConcurrentHashMap and ConcurrentSkipListMap CopyOnWriteArrayList <E> and CopyOnWriteArraySet <E> provide thread-safe collections (reads outnumber mutations) Callable <T> plus Future <T> can return and hold the result of an asynchronous computation (can test, time-out, and cancel) you can give a Runnable to a thread pool, and one of its idle threads executes it; afterwards, that thread can serve again synchronizers: CyclicBarrier, CountDownLatch, Exchanger, SynchronousQueue, and Semaphore AtomicInteger, AtomicLong, AtomicReference, etc.: lock-free Atomic variables support lock-free thread-safe programming on single variables (objects) extends the notion of volatile: provide atomic and synchronized access to single values (visibility!) enable implementations to use efficient atomic machine instructions that available on processors (but no guarantees: might entail internal locking..) AtomicLong seqno = new AtomicLong (0);.. long next () { return seqno.getandadd(1); // atomic may not work when state involves invariants.. atomic variables do not replace Integer, Long, etc. do not provide hashcode or compareto (since expected to change, no good as Map keys) thread-safe programming on single variables A producer-consumer solution class IntProducer implements Runnable { private BlockingQueue <Integer> queue; public IntProducer (BlockingQueue <Integer> q) { queue = q; new Thread (this).start (); public void run () { // "put" may block for (int x = 0; x < 100; x++) { Thread.sleep (delay);.. queue.put (x); catch (InterruptedException e) { A producer-consumer solution (cont.) class IntConsumer implements Runnable { private BlockingQueue <Integer> queue; public IntConsumer (BlockingQueue <Integer> q) { queue = q; new Thread (this).start (); public void run () { // "take" may block while (true) { int value = queue.take ();.. catch (InterruptedException ex) {.. BlockingQueue <Integer> q = new ArrayBlockingQueue <Integer> (10); // capacity

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis Built-in Concurrency Primitives in Java Programming Language by Yourii Martiak and Mahir Atmis Overview One of the many strengths of Java is the built into the programming language support for concurrency

More information

Outline of this lecture G52CON: Concepts of Concurrency

Outline of this lecture G52CON: Concepts of Concurrency Outline of this lecture G52CON: Concepts of Concurrency Lecture 10 Synchronisation in Java Natasha Alechina School of Computer Science nza@cs.nott.ac.uk mutual exclusion in Java condition synchronisation

More information

Java Concurrency Framework. Sidartha Gracias

Java Concurrency Framework. Sidartha Gracias Java Concurrency Framework Sidartha Gracias Executive Summary This is a beginners introduction to the java concurrency framework Some familiarity with concurrent programs is assumed However the presentation

More information

CS11 Java. Fall 2014-2015 Lecture 7

CS11 Java. Fall 2014-2015 Lecture 7 CS11 Java Fall 2014-2015 Lecture 7 Today s Topics! All about Java Threads! Some Lab 7 tips Java Threading Recap! A program can use multiple threads to do several things at once " A thread can have local

More information

8. Condition Objects. Prof. O. Nierstrasz. Selected material 2005 Bowbeer, Goetz, Holmes, Lea and Peierls

8. Condition Objects. Prof. O. Nierstrasz. Selected material 2005 Bowbeer, Goetz, Holmes, Lea and Peierls 8. Condition Objects Prof. O. Nierstrasz Selected material 2005 Bowbeer, Goetz, Holmes, Lea and Peierls Roadmap > Condition Objects Simple Condition Objects The Nested Monitor Problem Permits and Semaphores

More information

Parallel Programming

Parallel Programming Parallel Programming 0024 Recitation Week 7 Spring Semester 2010 R 7 :: 1 0024 Spring 2010 Today s program Assignment 6 Review of semaphores Semaphores Semaphoren and (Java) monitors Semaphore implementation

More information

Deadlock Victim. dimanche 6 mai 12

Deadlock Victim. dimanche 6 mai 12 Deadlock Victim by Dr Heinz Kabutz && Olivier Croisier The Java Specialists Newsletter && The Coder's Breakfast heinz@javaspecialists.eu && olivier.croisier@zenika.com 1 You discover a race condition 2

More information

Unit 6: Conditions, Barriers, and RendezVous

Unit 6: Conditions, Barriers, and RendezVous SPP (Synchro et Prog Parallèle) Unit 6: Conditions, Barriers, and RendezVous François Taïani So far We have seen several synchronisation mechanisms locks (plain, re-entrant, read/write) semaphores monitors

More information

Chapter 6 Concurrent Programming

Chapter 6 Concurrent Programming Chapter 6 Concurrent Programming Outline 6.1 Introduction 6.2 Monitors 6.2.1 Condition Variables 6.2.2 Simple Resource Allocation with Monitors 6.2.3 Monitor Example: Circular Buffer 6.2.4 Monitor Example:

More information

Java Memory Model: Content

Java Memory Model: Content Java Memory Model: Content Memory Models Double Checked Locking Problem Java Memory Model: Happens Before Relation Volatile: in depth 16 March 2012 1 Java Memory Model JMM specifies guarantees given by

More information

Monitors, Java, Threads and Processes

Monitors, Java, Threads and Processes Monitors, Java, Threads and Processes 185 An object-oriented view of shared memory A semaphore can be seen as a shared object accessible through two methods: wait and signal. The idea behind the concept

More information

Lecture 6: Semaphores and Monitors

Lecture 6: Semaphores and Monitors HW 2 Due Tuesday 10/18 Lecture 6: Semaphores and Monitors CSE 120: Principles of Operating Systems Alex C. Snoeren Higher-Level Synchronization We looked at using locks to provide mutual exclusion Locks

More information

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I) SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics

More information

Mutual Exclusion using Monitors

Mutual Exclusion using Monitors Mutual Exclusion using Monitors Some programming languages, such as Concurrent Pascal, Modula-2 and Java provide mutual exclusion facilities called monitors. They are similar to modules in languages that

More information

Threads & Tasks: Executor Framework

Threads & Tasks: Executor Framework Threads & Tasks: Executor Framework Introduction & Motivation WebServer Executor Framework Callable and Future 12 April 2012 1 Threads & Tasks Motivations for using threads Actor-based Goal: Create an

More information

Java Virtual Machine Locks

Java Virtual Machine Locks Java Virtual Machine Locks SS 2008 Synchronized Gerald SCHARITZER (e0127228) 2008-05-27 Synchronized 1 / 13 Table of Contents 1 Scope...3 1.1 Constraints...3 1.2 In Scope...3 1.3 Out of Scope...3 2 Logical

More information

Last Class: Semaphores

Last Class: Semaphores Last Class: Semaphores A semaphore S supports two atomic operations: S Wait(): get a semaphore, wait if busy semaphore S is available. S Signal(): release the semaphore, wake up a process if one is waiting

More information

Monitors & Condition Synchronization

Monitors & Condition Synchronization Chapter 5 Monitors & Condition Synchronization 1 monitors & condition synchronization Concepts: monitors: encapsulated data + access procedures mutual exclusion + condition synchronization nested monitors

More information

Shared Address Space Computing: Programming

Shared Address Space Computing: Programming Shared Address Space Computing: Programming Alistair Rendell See Chapter 6 or Lin and Synder, Chapter 7 of Grama, Gupta, Karypis and Kumar, and Chapter 8 of Wilkinson and Allen Fork/Join Programming Model

More information

Real Time Programming: Concepts

Real Time Programming: Concepts Real Time Programming: Concepts Radek Pelánek Plan at first we will study basic concepts related to real time programming then we will have a look at specific programming languages and study how they realize

More information

Concurrent Programming

Concurrent Programming Concurrent Programming Shared Memory Passing the baton Monitors Verónica Gaspes www.hh.se/staff/vero CERES, November 2, 2007 ceres Outline 1 Recap 2 Readers & Writers Readers & writers (mutual exclusion)

More information

Chapter 6, The Operating System Machine Level

Chapter 6, The Operating System Machine Level Chapter 6, The Operating System Machine Level 6.1 Virtual Memory 6.2 Virtual I/O Instructions 6.3 Virtual Instructions For Parallel Processing 6.4 Example Operating Systems 6.5 Summary Virtual Memory General

More information

! Past few lectures: Ø Locks: provide mutual exclusion Ø Condition variables: provide conditional synchronization

! Past few lectures: Ø Locks: provide mutual exclusion Ø Condition variables: provide conditional synchronization 1 Synchronization Constructs! Synchronization Ø Coordinating execution of multiple threads that share data structures Semaphores and Monitors: High-level Synchronization Constructs! Past few lectures:

More information

Facing the Challenges for Real-Time Software Development on Multi-Cores

Facing the Challenges for Real-Time Software Development on Multi-Cores Facing the Challenges for Real-Time Software Development on Multi-Cores Dr. Fridtjof Siebert aicas GmbH Haid-und-Neu-Str. 18 76131 Karlsruhe, Germany siebert@aicas.com Abstract Multicore systems introduce

More information

Semaphores and Monitors: High-level Synchronization Constructs

Semaphores and Monitors: High-level Synchronization Constructs Semaphores and Monitors: High-level Synchronization Constructs 1 Synchronization Constructs Synchronization Coordinating execution of multiple threads that share data structures Past few lectures: Locks:

More information

Monitors and Exceptions : How to Implement Java efficiently. Andreas Krall and Mark Probst Technische Universitaet Wien

Monitors and Exceptions : How to Implement Java efficiently. Andreas Krall and Mark Probst Technische Universitaet Wien Monitors and Exceptions : How to Implement Java efficiently Andreas Krall and Mark Probst Technische Universitaet Wien 1 Outline Exceptions in CACAO Exception implementation techniques CACAO s implementation

More information

Threads 1. When writing games you need to do more than one thing at once.

Threads 1. When writing games you need to do more than one thing at once. Threads 1 Threads Slide 1 When writing games you need to do more than one thing at once. Threads offer a way of automatically allowing more than one thing to happen at the same time. Java has threads as

More information

OBJECT ORIENTED PROGRAMMING LANGUAGE

OBJECT ORIENTED PROGRAMMING LANGUAGE UNIT-6 (MULTI THREADING) Multi Threading: Java Language Classes The java.lang package contains the collection of base types (language types) that are always imported into any given compilation unit. This

More information

3C03 Concurrency: Condition Synchronisation

3C03 Concurrency: Condition Synchronisation 3C03 Concurrency: Condition Synchronisation Mark Handley 1 Goals n Introduce concepts of Condition synchronisation Fairness Starvation n Modelling: Relationship between guarded actions and condition synchronisation?

More information

How To Write A Multi Threaded Software On A Single Core (Or Multi Threaded) System

How To Write A Multi Threaded Software On A Single Core (Or Multi Threaded) System Multicore Systems Challenges for the Real-Time Software Developer Dr. Fridtjof Siebert aicas GmbH Haid-und-Neu-Str. 18 76131 Karlsruhe, Germany siebert@aicas.com Abstract Multicore systems have become

More information

Concurrent programming in Java

Concurrent programming in Java Concurrent programming in Java INF4140 04.10.12 Lecture 5 0 Book: Andrews - ch.05 (5.4) Book: Magee & Kramer ch.04 - ch.07 INF4140 (04.10.12) Concurrent programming in Java Lecture 5 1 / 33 Outline 1 Monitors:

More information

SYSTEM ecos Embedded Configurable Operating System

SYSTEM ecos Embedded Configurable Operating System BELONGS TO THE CYGNUS SOLUTIONS founded about 1989 initiative connected with an idea of free software ( commercial support for the free software ). Recently merged with RedHat. CYGNUS was also the original

More information

Topics. Producing Production Quality Software. Concurrent Environments. Why Use Concurrency? Models of concurrency Concurrency in Java

Topics. Producing Production Quality Software. Concurrent Environments. Why Use Concurrency? Models of concurrency Concurrency in Java Topics Producing Production Quality Software Models of concurrency Concurrency in Java Lecture 12: Concurrent and Distributed Programming Prof. Arthur P. Goldberg Fall, 2005 2 Why Use Concurrency? Concurrent

More information

Thread Synchronization and the Java Monitor

Thread Synchronization and the Java Monitor Articles News Weblogs Buzz Chapters Forums Table of Contents Order the Book Print Email Screen Friendly Version Previous Next Chapter 20 of Inside the Java Virtual Machine Thread Synchronization by Bill

More information

Overview. CMSC 330: Organization of Programming Languages. Synchronization Example (Java 1.5) Lock Interface (Java 1.5) ReentrantLock Class (Java 1.

Overview. CMSC 330: Organization of Programming Languages. Synchronization Example (Java 1.5) Lock Interface (Java 1.5) ReentrantLock Class (Java 1. CMSC 330: Organization of Programming Languages Java 1.5, Ruby, and MapReduce Overview Java 1.5 ReentrantLock class Condition interface - await( ), signalall( ) Ruby multithreading Concurrent programming

More information

JAVA - MULTITHREADING

JAVA - MULTITHREADING JAVA - MULTITHREADING http://www.tutorialspoint.com/java/java_multithreading.htm Copyright tutorialspoint.com Java is amulti threaded programming language which means we can develop multi threaded program

More information

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification Introduction Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification Advanced Topics in Software Engineering 1 Concurrent Programs Characterized by

More information

Performance Improvement In Java Application

Performance Improvement In Java Application Performance Improvement In Java Application Megha Fulfagar Accenture Delivery Center for Technology in India Accenture, its logo, and High Performance Delivered are trademarks of Accenture. Agenda Performance

More information

aicas Technology Multi Core und Echtzeit Böse Überraschungen vermeiden Dr. Fridtjof Siebert CTO, aicas OOP 2011, 25 th January 2011

aicas Technology Multi Core und Echtzeit Böse Überraschungen vermeiden Dr. Fridtjof Siebert CTO, aicas OOP 2011, 25 th January 2011 aicas Technology Multi Core und Echtzeit Böse Überraschungen vermeiden Dr. Fridtjof Siebert CTO, aicas OOP 2011, 25 th January 2011 2 aicas Group aicas GmbH founded in 2001 in Karlsruhe Focus: Embedded

More information

Lecture 6: Introduction to Monitors and Semaphores

Lecture 6: Introduction to Monitors and Semaphores Concurrent Programming 19530-V (WS01) Lecture 6: Introduction to Monitors and Semaphores Dr. Richard S. Hall rickhall@inf.fu-berlin.de Concurrent programming November 27, 2001 Abstracting Locking Details

More information

Linux Scheduler. Linux Scheduler

Linux Scheduler. Linux Scheduler or or Affinity Basic Interactive es 1 / 40 Reality... or or Affinity Basic Interactive es The Linux scheduler tries to be very efficient To do that, it uses some complex data structures Some of what it

More information

MonitorExplorer: A State Exploration-Based Approach to Testing Java Monitors

MonitorExplorer: A State Exploration-Based Approach to Testing Java Monitors Department of Computer Science and Engineering University of Texas at Arlington Arlington, TX 76019 MonitorExplorer: A State Exploration-Based Approach to Testing Java Monitors Y. Lei, R. Carver, D. Kung,

More information

Monitors (Deprecated)

Monitors (Deprecated) D Monitors (Deprecated) Around the time concurrent programming was becoming a big deal, objectoriented programming was also gaining ground. Not surprisingly, people started to think about ways to merge

More information

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1 General Computer Architecture I/O Management COMP755 Advanced Operating Systems Goals for I/O Users should access all devices in a uniform manner. Devices should be named in a uniform manner. The OS, without

More information

Monitors and Semaphores

Monitors and Semaphores Monitors and Semaphores Annotated Condition Variable Example Condition *cv; Lock* cvmx; int waiter = 0; await() { cvmx->lock(); waiter = waiter + 1; /* I m sleeping */ cv->wait(cvmx); /* sleep */ cvmx->unlock();

More information

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive

More information

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Operating Systems Concepts: Chapter 7: Scheduling Strategies Operating Systems Concepts: Chapter 7: Scheduling Strategies Olav Beckmann Huxley 449 http://www.doc.ic.ac.uk/~ob3 Acknowledgements: There are lots. See end of Chapter 1. Home Page for the course: http://www.doc.ic.ac.uk/~ob3/teaching/operatingsystemsconcepts/

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND THE UNIVERSITY OF AUCKLAND 07.340 T07.340 EXAMINATION FOR BA BSc ETC 1995 COMPUTER SCIENCE Operating Systems ( Time allowed : THREE hours ) NOTES: Answer SIX questions. The total mark for each question

More information

Kernel Synchronization and Interrupt Handling

Kernel Synchronization and Interrupt Handling Kernel Synchronization and Interrupt Handling Oliver Sengpie, Jan van Esdonk Arbeitsbereich Wissenschaftliches Rechnen Fachbereich Informatik Fakultt fr Mathematik, Informatik und Naturwissenschaften Universitt

More information

Chapter 2: OS Overview

Chapter 2: OS Overview Chapter 2: OS Overview CmSc 335 Operating Systems 1. Operating system objectives and functions Operating systems control and support the usage of computer systems. a. usage users of a computer system:

More information

First-class User Level Threads

First-class User Level Threads First-class User Level Threads based on paper: First-Class User Level Threads by Marsh, Scott, LeBlanc, and Markatos research paper, not merely an implementation report User-level Threads Threads managed

More information

OPERATING SYSTEMS PROCESS SYNCHRONIZATION

OPERATING SYSTEMS PROCESS SYNCHRONIZATION OPERATING SYSTEMS PROCESS Jerry Breecher 6: Process Synchronization 1 OPERATING SYSTEM Synchronization What Is In This Chapter? This is about getting processes to coordinate with each other. How do processes

More information

A Survey of Parallel Processing in Linux

A Survey of Parallel Processing in Linux A Survey of Parallel Processing in Linux Kojiro Akasaka Computer Science Department San Jose State University San Jose, CA 95192 408 924 1000 kojiro.akasaka@sjsu.edu ABSTRACT Any kernel with parallel processing

More information

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Processes and Non-Preemptive Scheduling. Otto J. Anshus Processes and Non-Preemptive Scheduling Otto J. Anshus 1 Concurrency and Process Challenge: Physical reality is Concurrent Smart to do concurrent software instead of sequential? At least we want to have

More information

4. Monitors. Monitors support data encapsulation and information hiding and are easily adapted to an object-oriented environment.

4. Monitors. Monitors support data encapsulation and information hiding and are easily adapted to an object-oriented environment. 4. Monitors Problems with semaphores: - shared variables and the semaphores that protect them are global variables - Operations on shared variables and semaphores distributed throughout program - difficult

More information

Operating System Manual. Realtime Communication System for netx. Kernel API Function Reference. www.hilscher.com.

Operating System Manual. Realtime Communication System for netx. Kernel API Function Reference. www.hilscher.com. Operating System Manual Realtime Communication System for netx Kernel API Function Reference Language: English www.hilscher.com rcx - Kernel API Function Reference 2 Copyright Information Copyright 2005-2007

More information

CS 111 Classes I 1. Software Organization View to this point:

CS 111 Classes I 1. Software Organization View to this point: CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects

More information

Software and the Concurrency Revolution

Software and the Concurrency Revolution Software and the Concurrency Revolution A: The world s fastest supercomputer, with up to 4 processors, 128MB RAM, 942 MFLOPS (peak). 2 Q: What is a 1984 Cray X-MP? (Or a fractional 2005 vintage Xbox )

More information

Chapter 8 Implementing FSP Models in Java

Chapter 8 Implementing FSP Models in Java Chapter 8 Implementing FSP Models in Java 1 8.1.1: The Carpark Model A controller is required for a carpark, which only permits cars to enter when the carpark is not full and does not permit cars to leave

More information

10.04.2008. Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

10.04.2008. Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details Thomas Fahrig Senior Developer Hypervisor Team Hypervisor Architecture Terminology Goals Basics Details Scheduling Interval External Interrupt Handling Reserves, Weights and Caps Context Switch Waiting

More information

Chapter 11 I/O Management and Disk Scheduling

Chapter 11 I/O Management and Disk Scheduling Operating Systems: Internals and Design Principles, 6/E William Stallings Chapter 11 I/O Management and Disk Scheduling Dave Bremer Otago Polytechnic, NZ 2008, Prentice Hall I/O Devices Roadmap Organization

More information

Thesis Proposal: Improving the Performance of Synchronization in Concurrent Haskell

Thesis Proposal: Improving the Performance of Synchronization in Concurrent Haskell Thesis Proposal: Improving the Performance of Synchronization in Concurrent Haskell Ryan Yates 5-5-2014 1/21 Introduction Outline Thesis Why Haskell? Preliminary work Hybrid TM for GHC Obstacles to Performance

More information

Distributed Systems [Fall 2012]

Distributed Systems [Fall 2012] Distributed Systems [Fall 2012] [W4995-2] Lec 6: YFS Lab Introduction and Local Synchronization Primitives Slide acks: Jinyang Li, Dave Andersen, Randy Bryant (http://www.news.cs.nyu.edu/~jinyang/fa10/notes/ds-lec2.ppt,

More information

Transparent Redirection of Network Sockets 1

Transparent Redirection of Network Sockets 1 Transparent Redirection of Network Sockets Timothy S. Mitrovich, Kenneth M. Ford, and Niranjan Suri Institute for Human & Machine Cognition University of West Florida {tmitrovi,kford,nsuri@ai.uwf.edu.

More information

6 Synchronization with Semaphores

6 Synchronization with Semaphores 32 6 Synchronization with Semaphores The too-much-milk solution is much too complicated. The problem is that the mutual exclusion mechanism was too simple-minded: it used only atomic reads and writes.

More information

Centralized Systems. A Centralized Computer System. Chapter 18: Database System Architectures

Centralized Systems. A Centralized Computer System. Chapter 18: Database System Architectures Chapter 18: Database System Architectures Centralized Systems! Centralized Systems! Client--Server Systems! Parallel Systems! Distributed Systems! Network Types! Run on a single computer system and do

More information

Java SE 8 Programming

Java SE 8 Programming Oracle University Contact Us: 1.800.529.0165 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features and Application Programming

More information

Why Computers Are Getting Slower (and what we can do about it) Rik van Riel Sr. Software Engineer, Red Hat

Why Computers Are Getting Slower (and what we can do about it) Rik van Riel Sr. Software Engineer, Red Hat Why Computers Are Getting Slower (and what we can do about it) Rik van Riel Sr. Software Engineer, Red Hat Why Computers Are Getting Slower The traditional approach better performance Why computers are

More information

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization Lesson Objectives To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization AE3B33OSD Lesson 1 / Page 2 What is an Operating System? A

More information

Comparison of Concurrency Frameworks for the Java Virtual Machine

Comparison of Concurrency Frameworks for the Java Virtual Machine Universität Ulm Fakultät für Ingenieurwissenschaften und Informatik Institut für Verteilte Systeme, Bachelorarbeit im Studiengang Informatik Comparison of Concurrency Frameworks for the Java Virtual Machine

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Performance issues in writing Android Apps

Performance issues in writing Android Apps Performance issues in writing Android Apps Octav Chipara The process of developing Android apps problem definition focus: define the problem what is the input/out? what is the criteria for success? develop

More information

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin A Comparison Of Shared Memory Parallel Programming Models Jace A Mogill David Haglin 1 Parallel Programming Gap Not many innovations... Memory semantics unchanged for over 50 years 2010 Multi-Core x86

More information

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX Overview CISC Developments Over Twenty Years Classic CISC design: Digital VAX VAXÕs RISC successor: PRISM/Alpha IntelÕs ubiquitous 80x86 architecture Ð 8086 through the Pentium Pro (P6) RJS 2/3/97 Philosophy

More information

Building a Multi-Threaded Web Server

Building a Multi-Threaded Web Server Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous

More information

Understanding Hardware Transactional Memory

Understanding Hardware Transactional Memory Understanding Hardware Transactional Memory Gil Tene, CTO & co-founder, Azul Systems @giltene 2015 Azul Systems, Inc. Agenda Brief introduction What is Hardware Transactional Memory (HTM)? Cache coherence

More information

Embedded Systems. 6. Real-Time Operating Systems

Embedded Systems. 6. Real-Time Operating Systems Embedded Systems 6. Real-Time Operating Systems Lothar Thiele 6-1 Contents of Course 1. Embedded Systems Introduction 2. Software Introduction 7. System Components 10. Models 3. Real-Time Models 4. Periodic/Aperiodic

More information

Linux Process Scheduling Policy

Linux Process Scheduling Policy Lecture Overview Introduction to Linux process scheduling Policy versus algorithm Linux overall process scheduling objectives Timesharing Dynamic priority Favor I/O-bound process Linux scheduling algorithm

More information

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps.

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps. SQL Query Processing The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps. 1. The first step is to Parse the statement into keywords,

More information

Comp 204: Computer Systems and Their Implementation. Lecture 12: Scheduling Algorithms cont d

Comp 204: Computer Systems and Their Implementation. Lecture 12: Scheduling Algorithms cont d Comp 204: Computer Systems and Their Implementation Lecture 12: Scheduling Algorithms cont d 1 Today Scheduling continued Multilevel queues Examples Thread scheduling 2 Question A starvation-free job-scheduling

More information

Advanced Multiprocessor Programming

Advanced Multiprocessor Programming Advanced Multiprocessor Programming Jesper Larsson Träff traff@par.tuwien.ac.at Research Group Parallel Computing aculty of nformatics, nstitute of nformation Systems Vienna University of Technology (TU

More information

GTask Developing asynchronous applications for multi-core efficiency

GTask Developing asynchronous applications for multi-core efficiency GTask Developing asynchronous applications for multi-core efficiency February 2009 SCALE 7x Los Angeles Christian Hergert What Is It? GTask is a mini framework to help you write asynchronous code. Dependencies

More information

1.1. Over view. 1.2. Example 1: CPU Slot Distribution A example to test the distribution of cpu slot.

1.1. Over view. 1.2. Example 1: CPU Slot Distribution A example to test the distribution of cpu slot. 1. JVM, Threads, and Monitors See also: http://java.sun.com/docs/books/vmspec/2nd-edition/html/vmspec- TOC.doc.html I have copied material from there. Thanks to Tim Lindholm Frank Yellin. 1.1. Over view

More information

Optimizing Performance. Training Division New Delhi

Optimizing Performance. Training Division New Delhi Optimizing Performance Training Division New Delhi Performance tuning : Goals Minimize the response time for each query Maximize the throughput of the entire database server by minimizing network traffic,

More information

Operating System Resource Management. Burton Smith Technical Fellow Microsoft Corporation

Operating System Resource Management. Burton Smith Technical Fellow Microsoft Corporation Operating System Resource Management Burton Smith Technical Fellow Microsoft Corporation Background Resource Management (RM) is a primary operating system responsibility It lets competing applications

More information

Synchronization. Todd C. Mowry CS 740 November 24, 1998. Topics. Locks Barriers

Synchronization. Todd C. Mowry CS 740 November 24, 1998. Topics. Locks Barriers Synchronization Todd C. Mowry CS 740 November 24, 1998 Topics Locks Barriers Types of Synchronization Mutual Exclusion Locks Event Synchronization Global or group-based (barriers) Point-to-point tightly

More information

CSC 2405: Computer Systems II

CSC 2405: Computer Systems II CSC 2405: Computer Systems II Spring 2013 (TR 8:30-9:45 in G86) Mirela Damian http://www.csc.villanova.edu/~mdamian/csc2405/ Introductions Mirela Damian Room 167A in the Mendel Science Building mirela.damian@villanova.edu

More information

Concurrency on the JVM

Concurrency on the JVM Concurrency on the JVM Executors Fork / Join Framework Actors Th Letschert, THM Concurrency on the JVM What is concurrency Things get done concurrently or in parallel Concurrent vs parallel The same, only

More information

Using Power to Improve C Programming Education

Using Power to Improve C Programming Education Using Power to Improve C Programming Education Jonas Skeppstedt Department of Computer Science Lund University Lund, Sweden jonas.skeppstedt@cs.lth.se jonasskeppstedt.net jonasskeppstedt.net jonas.skeppstedt@cs.lth.se

More information

Keil C51 Cross Compiler

Keil C51 Cross Compiler Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation

More information

An Introduction to Programming with C# Threads

An Introduction to Programming with C# Threads An Introduction to Programming with C# Threads Andrew D. Birrell This paper provides an introduction to writing concurrent programs with threads. A threads facility allows you to write programs with multiple

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

Storage. The text highlighted in green in these slides contain external hyperlinks. 1 / 14

Storage. The text highlighted in green in these slides contain external hyperlinks. 1 / 14 Storage Compared to the performance parameters of the other components we have been studying, storage systems are much slower devices. Typical access times to rotating disk storage devices are in the millisecond

More information

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error

More information

Low level Java programming With examples from OpenHFT

Low level Java programming With examples from OpenHFT Low level Java programming With examples from OpenHFT Peter Lawrey CEO and Principal Consultant Higher Frequency Trading. Presentation to Joker 2014 St Petersburg, October 2014. About Us Higher Frequency

More information

System Software and TinyAUTOSAR

System Software and TinyAUTOSAR System Software and TinyAUTOSAR Florian Kluge University of Augsburg, Germany parmerasa Dissemination Event, Barcelona, 2014-09-23 Overview parmerasa System Architecture Library RTE Implementations TinyIMA

More information

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

Operating Systems 4 th Class

Operating Systems 4 th Class Operating Systems 4 th Class Lecture 1 Operating Systems Operating systems are essential part of any computer system. Therefore, a course in operating systems is an essential part of any computer science

More information

Simple Cooperative Scheduler for Arduino ARM & AVR. Aka «SCoop»

Simple Cooperative Scheduler for Arduino ARM & AVR. Aka «SCoop» Simple Cooperative Scheduler for Arduino ARM & AVR Aka «SCoop» Introduction Yet another library This library aims to provide a light and simple environment for creating powerful multi-threaded programs

More information

Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value

Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value CMSC 33: Organization of Programming Languages Programming Language Features (cont.) Names & binding Namespaces Static (lexical) scopes Dynamic scopes Polymorphism Parametric Subtype Ad-hoc Parameter Passing

More information