Intro to multi-threaded programming in Java

Size: px
Start display at page:

Download "Intro to multi-threaded programming in Java"

Transcription

1 Intro to multi-threaded programming in Java

2 Intro 1: Multitasking Most operating systems allow multitasking Multiple tasks are run in parallel (given enough processor cores) Word processor, file manager, web browser Background MP3 player, virus checker 2 Process 1 Program No access Tasks are separate programs with their own code, data, stack Process 2 Program Memory heap Memory heap

3 Intro 2: Threads Multi-threading (lightweight processes) A single program can have multiple threads of execution Executed in parallel (given enough CPU cores) Same heap, where objects are stored Different stack, keeping track local variables + method calls 3 Word Processor GUI Thread Print thread Background spell checker Shared heap No access Web Server Request handler Request handler Request handler Shared heap

4 Intro 3: Threads and Java Java is fundamentally multi-threaded Create threads using the Thread class Manage access to resources using the synchronized keyword Handle communication between threads using wait(), notify() methods 4 Threads for a standard non-gui program (Java 7, Windows): Group: system Max Priority: 10 Reference Handler [pri 10, Daemon] -- Handles weak references Finalizer [pri 8, Daemon] -- Runs finalizers Signal Dispatcher [pri 9, Daemon] Attach Listener [pri 5, Daemon] Group: main Max Priority: 10 main[pri 5] -- The thread that calls main() Additional Threads for a Swing GUI program (Java 7, Windows): Java2D Disposer [pri 10, Daemon] AWT-Windows [pri 6, Daemon] Daemon: Background services, won t prevent the program from terminating

5 Intro 4: Creating Threads To create a thread, first define what it should do The object-oriented way: An object with a specific method to run public class DocSaver implements Runnable { public void run() { save the document to disk Second step: Create an instance of your Runnable class final Runnable saver = new DocSaver(); Runnable interface: A single method 5 Third step: Create a Thread that will execute the Runnable final Thread t1 = new Thread(saver, "Document Saver"); Fourth step: Start the thread! t1.start(); Gives a name to the thread Creates an operating system thread with stack, etc.

6 Intro 5: Thread States Threads can be in one of four states: New created with new Thread(), not yet started Runnable has or wants the CPU The scheduler determines which runnable thread(s) will run Time allocation depends on thread priority Blocked waiting for something to happen Blocking on I/O Called sleep() Called obj.wait() waits for I/O to complete waits n milliseconds waits until notified 6 Thread. start() Done waiting Returns to runnable Dead stopped running The Runnable's run() method has returned But the Thread object still exists (not yet garbage collected)

7 Topic 1: Sharing Resources Threads often share resources 7 Document saving thread Spell checker thread Document editing thread Document object Swing thread (events, painting) What if a document changes while it is being saved? Requires support for coordination, mutual exclusion between threads,

8 Topic 2: Cooperation 8 Threads sometimes cooperate to achieve a common purpose Coordinating thread in image processing software Image Processing on core 1 Image Processing on core 2 Image Processing on core 3 Image Processing on core 4 How to communicate results? Requires support for communication between threads

9 When threads cooperate

10 Communication 1: Producer/Consumer Develop a multi-threaded queue (producer/consumer) 10 Potential delays Producer thread: Read data from disk, append to queue Consumer thread: Read data from queue, play a sound

11 Communication 2: Producer/Consumer 11 class Producer implements Runnable { private final MsgQueue queue; public Producer(MsgQueue q) { this.queue = q; Read data from disk, append to queue public void run() { while (true) { Msg data = [[read]]; queue.put(data); Read from queue, decode MP3, play sound class Consumer implements Runnable { private final MsgQueue queue; public Consumer(MsgQueue q) { this.queue = q; public void run() { while (true) { Msg data = queue.take(); [[play sound from data]];

12 Communication 3: First Attempt 12 First attempt: Let's use an ArrayList! public class MsgQueue { List<Msg> list = new ArrayList<Msg>(); public synchronized void put(msg msg) { list.add(msg); // At the end public synchronized Msg take() { return list.remove(0); Problem! If the queue is empty, there is no element to pop ArrayIndexOutOfBoundsException Solution! The consumer must wait for an element to arrive from the producer! Java provides obj.wait() and obj.notify() for thread communication tricky!

13 Communication 4: Concurrent Queues Fortunately, Java already provides concurrent queues! Usually don't need to use the low-level methods Easy to make mistakes interface BlockingQueue<E> extends Collection<E>: Supports blocking and timeouts 13 What happens if the operation can t be performed (now)? Insert (queue may be full) Remove (may be empty) Examine (may be empty) Throw exception Return null or false add(e) offer(e) put(e) Block (wait until the operation can be performed) Time out (after a specific interval) offer(e, time, unit) remove() poll() take() poll(time, unit) element() peek() not applicable not applicable

14 Concurrent (Blocking) Queues 14 Implemented by ArrayBlockingQueue SynchronousQueue LinkedBlockingQueue LinkedBlockingDeque DelayQueue PriorityBlockingQueue LinkedTransferQueue bounded size zero capacity, each insert matched with a remove each element is available when its delay expires where producers may wait for consumers

15 Shared Resources When is a Program Thread Safe? Mutual Exclusion: Conceptual View and Java Syntax

16 Thread Safety 1: Intro Threads accessing the same data must not interfere! Simple example: ArrayList class used from multiple threads public class ArrayList<E> { private int size = 0; private E[] elements = (E[]) new Object[100]; public void add(e obj) { elements[size] = obj; size++; public void clear() { elements = (E[]) new Object[100]; size = 0; 16

17 Thread Safety 2: Thread Switching 17 With a single CPU core The computer quickly switches between active threads (time slicing) This happens even inside methods! With multiple CPU cores Multiple threads can be running truly simultaneously Timer Swing Timer Swing begin update() continue begin repaint() begin update() begin repaint() continue continue continue

18 Thread Safety 3: Within Methods What happens within a method? 18 Java source (text): Hello.java Compiler: javac Hello.java Bytecode (binary intermediate format): Hello.class Standardized, can be distributed class HelloWorld { public static void main(string[] args) { System.out.println("Hello World!"); Method void main(java.lang.string[]) b2 00 0b 12 0f b c a b2 00 0b bb getstatic #12 <Field java.io.prints ldc #15 <String "Hello, world"> invokevirtual #20 <Method void iconst_0 istore_1 goto 39 getstatic #12 <Field java.io.prints new #23 <Class java.lang.stringbu

19 Thread Safety 4: Fine-Grained Switching 19 Even with one core: Can switch threads after any atomic (indivisible) bytecode operation Very fine-grained! Thread 1 executing size++ push size value onto stack increment top of stack Thread 2 executing a[i] = j push a onto stack push i onto stack push j onto stack arraystore Bytecode instructions store value at top of stack in size

20 Thread Safety 5: Race condition! Suppose two threads call add(a) / add(b) concurrently public void add(e obj) { elements[size] = obj; size++; Might expect: [A,B] or [B,A]. This is not guaranteed! Called a race condition: Depends on "who gets there first" (exactly how far does one thread get before it is interrupted?) 20 read size: 0 store A at [0] read size: 0 inc 1 store size: 1 read size: 1 store B at [1] read size: 1 inc 2 store size: 2 [A,B] read size: 0 store A at [0] read size: 0 read size: 0 store B at [0] read size: 0 inc 1 store size: 1 inc 1 store size: 1 [B] read size: 0 store A at [0] read size: 0 store B at [0] read size: 0 inc 1 store size: 1 read size: 1 inc 2 store size: 2 [B,null]

21 Thread Safety 6: One Requirement One common requirement for thread safety: Parallel execution should be equivalent to some serialization The result should be as if the concurrent calls from multiple threads had been made in some sequence from a single thread Only the result counts if you can still do it concurrently, it's better! 21 If you do this (multiple CPUs) or this (one CPU) The result should be as if you did this or as if you did this. add(a) add(a) add(b) add(b) add(a) add(b) add(b) add(a)

22 Thread Safety 7: Cleverness 22 How is this type of thread safety achieved? Sometimes through very clever algorithms and data structures ConcurrentLinkedQueue threadsafe linked queue ConcurrentLinkedDeque threadsafe linked double-ended queue ConcurrentHashMap ConcurrentSkipListMap Methods do execute like this add(a) add(b) or like this add(a) add(b) efficient multithreaded access without locking another variation...but regardless of scheduling, correct results are guaranteed! Beyond the scope of this course!

23 Thread Safety 8: Mutexes How is this type of thread safety achieved? Usually through mechanisms for mutual exclusion 23 Can t add() to the same list from two threads concurrently One thread will have to wait for the first add() to complete Make sure you can t do this or this You can only do this or this. add(a) add(a) add(b) add(b) add(a) add(b) add(b) add(a)

24 Mutex 1: Semaphore/Monitor 24 One mechanism for mutual exclusion: Semaphore / monitor semaphore.acquire() Waits until no other thread has the semaphore, then "locks" it for this thread semaphore.release() Releases the semaphore, so that some other thread can use it These functions use specific low-level machine instructions to avoid race conditions list.add(a): list.semaphore.acquire(); list.semaphore.release(); list.add(b): list.semaphore.acquire(); list.semaphore.release(); This allows you to use the semaphore at a higher level of abstraction

25 Mutex 2: Monitors in Java Mutual exclusion and semaphores / monitors in Java: Every object is associated with a monitor Acquired and released through synchronized blocks: synchronized(myobject) { // Acquire() myobject s monitor // Implicitly release() it again Synchronized blocks provide structure to monitors Automatically release()d when you exit the block: You can't forget to release them, even if an exception terminates the method 25

26 Mutex 3: Monitors in ArrayList Must use a monitor in the list example Which one? Create a new object public class ArrayList<E> { private int size = 0; private E[] elements = (E[]) new Object[100]; private Object monitor = new Object(); 26 public void add(e obj) { synchronized(monitor) { // acquire monitor elements[size] = obj; size++; // release monitor public void clear() { synchronized(monitor) { elements = (E[]) new Object[100]; size = 0;

27 Mutex 4: Acquiring a Monitor Suppose thread A calls add(a) First: synchronized(monitor) acquires the list s monitor Atomic test-and-set: acquired is false, so make it true Make thread A the owner of the monitor A: acquire A: read size 0 A: store A at 0 27 Conceptual view the monitor is not a Java object with fields! before synchronized(mon) { acquired owner lockqueue false Thread object: Thread A, runnable within synchronized(mon) { acquired owner lockqueue true Thread A runnable

28 Mutex 5: Wait Queue If the scheduler lets B run, before A is done: Method add() calls synchronized(mon) Tries to acquire the monitor Atomic test-and-set: acquired is true, so we fail Thread B is blocked, placed in a wait queue! 28 A: read size 0 B: try acquire B: block [other threads might run here] When thread B is blocked: The scheduler selects another runnable thread (not necessarily A!) acquired owner lockqueue true Thread A runnable Thread B blocked Thread C runnable Thread D runnable

29 Mutex 6: Wait Queue 29 Eventually, thread A is scheduled to run again Finishes its work (no interference!) and releases the monitor Thread B is unblocked (runnable), but thread A continues running acquired owner lockqueue Eventually, thread B is scheduled to run again Thread B is allowed to acquire the monitor acquired owner lockqueue false true Thread A runnable Thread B runnable Thread B runnable A: read size 0 B: try acquire B: block [other threads run] A: inc 1 A: store size 1 A: release A: keep working

30 Mutex 7: Cooperative Be careful: Mutual exclusion is cooperative 30 Not like placing the object in a safe More like this: ArraySet obj. ArraySet obj. header header elements: [] size: 0 elements: [] size: 0 public void getsize() { return size; No synchronized() block can be called in parallel with add() or any other method! Fields can be accessed Methods can be called Everyone must cooperate by checking the note (trying to acquire the monitor)!

31 Mutex 8: All Methods Synchronized? Must all methods use synchronization? Depends on your class // No synchronized() can be called in parallel with other methods public void getsize() { return size; // Calling unsynchronized getsize() in parallel with clear1() // returns either the old size, or the new size 0 OK! public void clear1() { synchronized(monitor) { elements = (E[]) new Object[100]; size = 0; // Calling unsynchronized getsize() in parallel with clear2() // may return an "intermediate" size, that the list never really had! // (One solution: synchronization in getsize() too) public void clear2() { synchronized(monitor) { while (size > 0) elements[--size] = null; 31

32 Mutex 9: Cooperative Protection How to ensure thread safety, if mutexes are cooperative? Anyone can just skip synchronization, deliberately or by mistake 32 Use standard public/private protection! Make sure all fields are private Public fields can be accessed regardless of synchronization Other threads can read intermediate values of public fields Other threads can change values while mutators are being executed But private fields are only accessed within the class which you control! Make sure all methods use synchronization where necessary

33 Conclusions: Complete Thread Safety How do you ensure complete thread safety? The same way you write a bug-free program Think! Consider all possible combinations of circumstances! Do everything right! Requires policy / design decisions, which must be followed Complicated because high parallelism is desired That is the reason why we use threads in the first place Don't want too much mutual exclusion 33 Sorry, but there are no simple answers!

34

35 Synchronization Overhead 35 Synchronization has some overhead! public class SynchTester { public static void main(string[] args) { for (int i = 0; i < 5; i++) doit(); private static void doit() { SynchTester tester = new SynchTester(); long start = System.currentTimeMillis(); ms int value = 1; 1368 ms for (int i = 0; i < 1_000_000_000L; i++) { 539 ms value = tester.increment(value); 545 ms 545 ms System.out.println((System.currentTimeMillis()-start) + "ms: " + value); public synchronized int increment(int var) { return var + 1; Without synchronized: 651 ms 571 ms 566 ms 553 ms 548 ms With synchronized: Huge proportional diff: The method is trivial in itself In this case, the method is dynamically optimized to remove the overhead. Not always possible!

36

37 Synchronization and Collections Collection classes: Often used in single-threaded context Three alternatives: 37 Don t use synchronization public void add(object obj) { // Lots of code adding an element Do use synchronization public void add(object obj) { synchronized(monitor) { // Code adding an element If you use from multiple threads: Risk incorrect results (lost elements, ) Unnecessary overhead in most cases Provide both versions! A lot of redundant code right?

38 Synchronization and Collections (2) 38 Solution: Do provide two versions, don t write collections twice Don t use synchronization public void add(object obj) { // Lots of code adding an element Do use synchronization public synchronizedvoid add(object obj) { // Quick call to the real class: // Delegation

39 Collections: Synchronization Wrappers 39 To achieve this: Use a synchronization wrapper synchlist public class SynchList implements List { private List storage; private Object monitor = ; public SynchList(List storage) { this.storage = storage; public void add(object obj) { synchronized(monitor) { storage.add(obj); "SynchList" Object header: storage (data) ArrayList Object header: (data) size 0 elements Uses the decorator design pattern Implements List can be used everywhere Header length [0] [1] [2] [3] (data) 4

40 Built-in Synchronization Wrappers Synchronization wrappers exist in the Collections framework! List<String> synchlist = Collections.synchronizedList(new ArrayList<String>()); 40

41

42 // Schedule a task to run repeatedly, starting now, // 500 ms from execution n begins to execution n+1 begins t.scheduleatfixedrate(task, new Date(), 500); Timers 42 To schedule arbitrary tasks: java.util.timer Starts a separate thread for each Timer not dependent on Swing timers import java.util.timer; final TimerTask task = new TimerTask() { public void run() { System.out.println( Running!"); ; Timer t = new Timer(); // Schedule a task to run a single time, after 500 ms t.schedule(task, 500); Don t manipulate an existing GUI here: Only permitted in the Swing thread! // Schedule a task to run repeatedly, starting now, // 500 ms from execution n ends to execution n+1 begins t.schedule(task, new Date(), 500);

Java Threads. COMP 585 Noteset #2 1

Java Threads. COMP 585 Noteset #2 1 Java Threads The topic of threads overlaps the boundary between software development and operation systems. Words like process, task, and thread may mean different things depending on the author and the

More information

Synchronization COMPSCI 386

Synchronization COMPSCI 386 Synchronization COMPSCI 386 Obvious? // push an item onto the stack while (top == SIZE) ; stack[top++] = item; // pop an item off the stack while (top == 0) ; item = stack[top--]; PRODUCER CONSUMER Suppose

More information

Threads Questions Important Questions

Threads Questions Important Questions Threads Questions Important Questions https://dzone.com/articles/threads-top-80-interview https://www.journaldev.com/1162/java-multithreading-concurrency-interviewquestions-answers https://www.javatpoint.com/java-multithreading-interview-questions

More information

THREADS AND CONCURRENCY

THREADS AND CONCURRENCY THREADS AND CONCURRENCY Lecture 22 CS2110 Spring 2013 Graphs summary 2 Dijkstra: given a vertex v, finds shortest path from v to x for each vertex x in the graph Key idea: maintain a 5-part invariant on

More information

Java Threads. Introduction to Java Threads

Java Threads. Introduction to Java Threads Java Threads Resources Java Threads by Scott Oaks & Henry Wong (O Reilly) API docs http://download.oracle.com/javase/6/docs/api/ java.lang.thread, java.lang.runnable java.lang.object, java.util.concurrent

More information

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions CMSC 330: Organization of Programming Languages Multithreaded Programming Patterns in Java CMSC 330 2 Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to

More information

THREADS & CONCURRENCY

THREADS & CONCURRENCY 27/04/2018 Sorry for the delay in getting slides for today 2 Another reason for the delay: Yesterday: 63 posts on the course Piazza yesterday. A7: If you received 100 for correctness (perhaps minus a late

More information

Virtual Machine Design

Virtual Machine Design Virtual Machine Design Lecture 4: Multithreading and Synchronization Antero Taivalsaari September 2003 Session #2026: J2MEPlatform, Connected Limited Device Configuration (CLDC) Lecture Goals Give an overview

More information

Programming in Parallel COMP755

Programming in Parallel COMP755 Programming in Parallel COMP755 All games have morals; and the game of Snakes and Ladders captures, as no other activity can hope to do, the eternal truth that for every ladder you hope to climb, a snake

More information

Introduction to Java Threads

Introduction to Java Threads Object-Oriented Programming Introduction to Java Threads RIT CS 1 "Concurrent" Execution Here s what could happen when you run this Java program and launch 3 instances on a single CPU architecture. The

More information

CMSC 132: Object-Oriented Programming II. Threads in Java

CMSC 132: Object-Oriented Programming II. Threads in Java CMSC 132: Object-Oriented Programming II Threads in Java 1 Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read & write files

More information

Java Concurrency in practice Chapter 9 GUI Applications

Java Concurrency in practice Chapter 9 GUI Applications Java Concurrency in practice Chapter 9 GUI Applications INF329 Spring 2007 Presented by Stian and Eirik 1 Chapter 9 GUI Applications GUI applications have their own peculiar threading issues To maintain

More information

MultiThreading 07/01/2013. Session objectives. Introduction. Introduction. Advanced Java Programming Course

MultiThreading 07/01/2013. Session objectives. Introduction. Introduction. Advanced Java Programming Course Advanced Java Programming Course MultiThreading By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Session objectives Introduction Creating thread Thread class

More information

JAVA and J2EE UNIT - 4 Multithreaded Programming And Event Handling

JAVA and J2EE UNIT - 4 Multithreaded Programming And Event Handling JAVA and J2EE UNIT - 4 Multithreaded Programming And Event Handling Multithreaded Programming Topics Multi Threaded Programming What are threads? How to make the classes threadable; Extending threads;

More information

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Advanced Java Programming Course MultiThreading By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Session objectives Introduction Creating thread Thread class

More information

CSE 153 Design of Operating Systems Fall 2018

CSE 153 Design of Operating Systems Fall 2018 CSE 153 Design of Operating Systems Fall 2018 Lecture 5: Threads/Synchronization Implementing threads l Kernel Level Threads l u u All thread operations are implemented in the kernel The OS schedules all

More information

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

27/04/2012. We re going to build Multithreading Application. Objectives. MultiThreading. Multithreading Applications. What are Threads?

27/04/2012. We re going to build Multithreading Application. Objectives. MultiThreading. Multithreading Applications. What are Threads? Objectives MultiThreading What are Threads? Interrupting threads Thread properties By Võ Văn Hải Faculty of Information Technologies Summer 2012 Threads priorities Synchronization Callables and Futures

More information

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007 CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Threads and Synchronization May 8, 2007 Computation Abstractions t1 t1 t4 t2 t1 t2 t5 t3 p1 p2 p3 p4 CPU 1 CPU 2 A computer Processes

More information

Concurrent Programming

Concurrent Programming Concurrency Concurrent Programming A sequential program has a single thread of control. Its execution is called a process. A concurrent program has multiple threads of control. They may be executed as

More information

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17 Concurrency & Parallelism So far, our programs have been sequential: they do one thing after another, one thing at a. Let s start writing programs that do more than one thing at at a. Threads, Concurrency,

More information

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03 CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03 Topics: Threading, Synchronization 1 Threading Suppose we want to create an automated program that hacks into a server. Many encryption

More information

CSE 153 Design of Operating Systems

CSE 153 Design of Operating Systems CSE 153 Design of Operating Systems Winter 19 Lecture 7/8: Synchronization (1) Administrivia How is Lab going? Be prepared with questions for this weeks Lab My impression from TAs is that you are on track

More information

Thread-Local. Lecture 27: Concurrency 3. Dealing with the Rest. Immutable. Whenever possible, don t share resources

Thread-Local. Lecture 27: Concurrency 3. Dealing with the Rest. Immutable. Whenever possible, don t share resources Thread-Local Lecture 27: Concurrency 3 CS 62 Fall 2016 Kim Bruce & Peter Mawhorter Some slides based on those from Dan Grossman, U. of Washington Whenever possible, don t share resources Easier to have

More information

Threads, Concurrency, and Parallelism

Threads, Concurrency, and Parallelism Threads, Concurrency, and Parallelism Lecture 24 CS2110 Spring 2017 Concurrency & Parallelism So far, our programs have been sequential: they do one thing after another, one thing at a time. Let s start

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Threads Synchronization Refers to mechanisms allowing a programmer to control the execution order of some operations across different threads in a concurrent

More information

THREADS & CONCURRENCY

THREADS & CONCURRENCY 4/26/16 Announcements BRING YOUR CORNELL ID TO THE PRELIM. 2 You need it to get in THREADS & CONCURRENCY Prelim 2 is next Tonight BRING YOUR CORNELL ID! A7 is due Thursday. Our Heap.java: on Piazza (A7

More information

Dealing with Issues for Interprocess Communication

Dealing with Issues for Interprocess Communication Dealing with Issues for Interprocess Communication Ref Section 2.3 Tanenbaum 7.1 Overview Processes frequently need to communicate with other processes. In a shell pipe the o/p of one process is passed

More information

CS 160: Interactive Programming

CS 160: Interactive Programming CS 160: Interactive Programming Professor John Canny 3/8/2006 1 Outline Callbacks and Delegates Multi-threaded programming Model-view controller 3/8/2006 2 Callbacks Your code Myclass data method1 method2

More information

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules

Concurrency Control. Synchronization. Brief Preview of Scheduling. Motivating Example. Motivating Example (Cont d) Interleaved Schedules Brief Preview of Scheduling Concurrency Control Nan Niu (nn@cs.toronto.edu) CSC309 -- Summer 2008 Multiple threads ready to run Some mechanism for switching between them Context switches Some policy for

More information

COMP 346 WINTER Tutorial 2 SHARED DATA MANIPULATION AND SYNCHRONIZATION

COMP 346 WINTER Tutorial 2 SHARED DATA MANIPULATION AND SYNCHRONIZATION COMP 346 WINTER 2018 1 Tutorial 2 SHARED DATA MANIPULATION AND SYNCHRONIZATION REVIEW - MULTITHREADING MODELS 2 Some operating system provide a combined user level thread and Kernel level thread facility.

More information

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011 Synchronization CS61, Lecture 18 Prof. Stephen Chong November 3, 2011 Announcements Assignment 5 Tell us your group by Sunday Nov 6 Due Thursday Nov 17 Talks of interest in next two days Towards Predictable,

More information

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers 1 Critical sections and atomicity We have been seeing that sharing mutable objects between different threads is tricky We need some

More information

Java Monitors. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Java Monitors. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico. Java Monitors Parallel and Distributed Computing Department of Computer Science and Engineering (DEI) Instituto Superior Técnico October 19, 2010 Monteiro, Costa (DEI / IST) Parallel and Distributed Computing

More information

Concurrency in Object Oriented Programs 1. Object-Oriented Software Development COMP4001 CSE UNSW Sydney Lecturer: John Potter

Concurrency in Object Oriented Programs 1. Object-Oriented Software Development COMP4001 CSE UNSW Sydney Lecturer: John Potter Concurrency in Object Oriented Programs 1 Object-Oriented Software Development COMP4001 CSE UNSW Sydney Lecturer: John Potter Outline Concurrency: the Future of Computing Java Concurrency Thread Safety

More information

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5 Threads CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5 1 Threads The Thread Model (1) (a) Three processes each with one thread (b) One process with three threads 2 1 The Thread Model (2)

More information

Chapter 32 Multithreading and Parallel Programming

Chapter 32 Multithreading and Parallel Programming Chapter 32 Multithreading and Parallel Programming 1 Objectives To get an overview of multithreading ( 32.2). To develop task classes by implementing the Runnable interface ( 32.3). To create threads to

More information

Process Management And Synchronization

Process Management And Synchronization Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the

More information

Lecture 8: September 30

Lecture 8: September 30 CMPSCI 377 Operating Systems Fall 2013 Lecture 8: September 30 Lecturer: Prashant Shenoy Scribe: Armand Halbert 8.1 Semaphores A semaphore is a more generalized form of a lock that can be used to regulate

More information

Multithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science

Multithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science Multithreaded Programming Part II CSE 219 Stony Brook University, Thread Scheduling In a Java application, main is a thread on its own Once multiple threads are made Runnable the thread scheduler of the

More information

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018 SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T 2. 3. 8 A N D 2. 3. 1 0 S P R I N G 2018 INTER-PROCESS COMMUNICATION 1. How a process pass information to another process

More information

CS11 Java. Fall Lecture 7

CS11 Java. Fall Lecture 7 CS11 Java Fall 2006-2007 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 (non-shared)

More information

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio Fall 2017 1 Outline Inter-Process Communication (20) Threads

More information

Le L c e t c ur u e e 7 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Multithreading

Le L c e t c ur u e e 7 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Multithreading Course Name: Advanced Java Lecture 7 Topics to be covered Multithreading Thread--An Introduction Thread A thread is defined as the path of execution of a program. It is a sequence of instructions that

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization Administrivia Homework 1 Due today by the end of day Hopefully you have started on project 1 by now? Kernel-level threads (preemptable

More information

Multi-threading in Java. Jeff HUANG

Multi-threading in Java. Jeff HUANG Multi-threading in Java Jeff HUANG Software Engineering Group @HKUST Do you use them? 2 Do u know their internals? 3 Let s see File DB How can they service so many clients simultaneously? l 4 Multi-threading

More information

Problems with Concurrency. February 19, 2014

Problems with Concurrency. February 19, 2014 with Concurrency February 19, 2014 s with concurrency interleavings race conditions dead GUI source of s non-determinism deterministic execution model 2 / 30 General ideas Shared variable Access interleavings

More information

Overview. Processes vs. Threads. Computation Abstractions. CMSC 433, Fall Michael Hicks 1

Overview. Processes vs. Threads. Computation Abstractions. CMSC 433, Fall Michael Hicks 1 CMSC 433 Programming Language Technologies and Paradigms Spring 2003 Threads and Synchronization April 1, 2003 Overview What are threads? Thread scheduling, data races, and synchronization Thread mechanisms

More information

Synchronization I. Jo, Heeseung

Synchronization I. Jo, Heeseung Synchronization I Jo, Heeseung Today's Topics Synchronization problem Locks 2 Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Also, to coordinate

More information

Reintroduction to Concurrency

Reintroduction to Concurrency Reintroduction to Concurrency The execution of a concurrent program consists of multiple processes active at the same time. 9/25/14 7 Dining philosophers problem Each philosopher spends some time thinking

More information

CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections. Tyler Robison Summer 2010

CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections. Tyler Robison Summer 2010 CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections Tyler Robison Summer 2010 1 Concurrency: where are we Done: The semantics of locks Locks in Java Using locks for mutual

More information

Computation Abstractions. CMSC 330: Organization of Programming Languages. So, What Is a Thread? Processes vs. Threads. A computer.

Computation Abstractions. CMSC 330: Organization of Programming Languages. So, What Is a Thread? Processes vs. Threads. A computer. CMSC 330: Organization of Programming Languages Threads Computation Abstractions t1 t2 t1 t3 t2 t1 p1 p2 p3 p4 CPU 1 CPU 2 A computer t4 t5 Processes (e.g., JVM s) Threads CMSC 330 2 Processes vs. Threads

More information

Need for synchronization: If threads comprise parts of our software systems, then they must communicate.

Need for synchronization: If threads comprise parts of our software systems, then they must communicate. Thread communication and synchronization There are two main aspects to Outline for Lecture 19 multithreaded programming in Java: I. Thread synchronization. thread lifecycle, and thread synchronization.

More information

Threads and Parallelism in Java

Threads and Parallelism in Java Threads and Parallelism in Java Java is one of the few main stream programming languages to explicitly provide for user-programmed parallelism in the form of threads. A Java programmer may organize a program

More information

Synchronization Spinlocks - Semaphores

Synchronization Spinlocks - Semaphores CS 4410 Operating Systems Synchronization Spinlocks - Semaphores Summer 2013 Cornell University 1 Today How can I synchronize the execution of multiple threads of the same process? Example Race condition

More information

Recap. Contents. Reenterancy of synchronized. Explicit Locks: ReentrantLock. Reenterancy of synchronise (ctd) Advanced Thread programming.

Recap. Contents. Reenterancy of synchronized. Explicit Locks: ReentrantLock. Reenterancy of synchronise (ctd) Advanced Thread programming. Lecture 07: Advanced Thread programming Software System Components 2 Behzad Bordbar School of Computer Science, University of Birmingham, UK Recap How to deal with race condition in Java Using synchronised

More information

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004 CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004 Lecture 9: Readers-Writers and Language Support for Synchronization 9.1.2 Constraints 1. Readers can access database

More information

JAVA CONCURRENCY FRAMEWORK. Kaushik Kanetkar

JAVA CONCURRENCY FRAMEWORK. Kaushik Kanetkar JAVA CONCURRENCY FRAMEWORK Kaushik Kanetkar Old days One CPU, executing one single program at a time No overlap of work/processes Lots of slack time CPU not completely utilized What is Concurrency Concurrency

More information

Parallel Programming Languages COMP360

Parallel Programming Languages COMP360 Parallel Programming Languages COMP360 The way the processor industry is going, is to add more and more cores, but nobody knows how to program those things. I mean, two, yeah; four, not really; eight,

More information

CS3733: Operating Systems

CS3733: Operating Systems Outline CS3733: Operating Systems Topics: Synchronization, Critical Sections and Semaphores (SGG Chapter 6) Instructor: Dr. Tongping Liu 1 Memory Model of Multithreaded Programs Synchronization for coordinated

More information

CPS221 Lecture: Threads

CPS221 Lecture: Threads Objectives CPS221 Lecture: Threads 1. To introduce threads in the context of processes 2. To introduce UML Activity Diagrams last revised 9/5/12 Materials: 1. Diagram showing state of memory for a process

More information

Sharing is the Key. Lecture 25: Parallelism. Canonical Example. Bad Interleavings. Common to have: CS 62 Fall 2016 Kim Bruce & Peter Mawhorter

Sharing is the Key. Lecture 25: Parallelism. Canonical Example. Bad Interleavings. Common to have: CS 62 Fall 2016 Kim Bruce & Peter Mawhorter Sharing is the Key Lecture 25: Parallelism CS 62 Fall 2016 Kim Bruce & Peter Mawhorter Some slides based on those from Dan Grossman, U. of Washington Common to have: Different threads access the same resources

More information

CSE332: Data Abstractions Lecture 19: Mutual Exclusion and Locking

CSE332: Data Abstractions Lecture 19: Mutual Exclusion and Locking CSE332: Data Abstractions Lecture 19: Mutual Exclusion and Locking James Fogarty Winter 2012 Including slides developed in part by Ruth Anderson, James Fogarty, Dan Grossman Banking Example This code is

More information

Handouts. 1 Handout for today! Recap. Homework #2 feedback. Last Time. What did you think? HW3a: ThreadBank. Today. Small assignment.

Handouts. 1 Handout for today! Recap. Homework #2 feedback. Last Time. What did you think? HW3a: ThreadBank. Today. Small assignment. Handouts CS193J: Programming in Java Summer Quarter 2003 Lecture 10 Thread Interruption, Cooperation (wait/notify), Swing Thread, Threading conclusions 1 Handout for today! #21: Threading 3 #22: HW3a:

More information

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T

Operating Systems. Operating Systems Summer 2017 Sina Meraji U of T Operating Systems Operating Systems Summer 2017 Sina Meraji U of T More Special Instructions Swap (or Exchange) instruction Operates on two words atomically Can also be used to solve critical section problem

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

COMP31212: Concurrency A Review of Java Concurrency. Giles Reger

COMP31212: Concurrency A Review of Java Concurrency. Giles Reger COMP31212: Concurrency A Review of Java Concurrency Giles Reger Outline What are Java Threads? In Java, concurrency is achieved by Threads A Java Thread object is just an object on the heap, like any other

More information

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University CS 333 Introduction to Operating Systems Class 3 Threads & Concurrency Jonathan Walpole Computer Science Portland State University 1 Process creation in UNIX All processes have a unique process id getpid(),

More information

COMP 213. Advanced Object-oriented Programming. Lecture 23. Shared Variables and Synchronization

COMP 213. Advanced Object-oriented Programming. Lecture 23. Shared Variables and Synchronization COMP 213 Advanced Object-oriented Programming Lecture 23 Shared Variables and Synchronization Communicating Threads In the previous lecture, we saw an example of a multi-threaded program where three threads

More information

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs CSE 451: Operating Systems Winter 2005 Lecture 7 Synchronization Steve Gribble Synchronization Threads cooperate in multithreaded programs to share resources, access shared data structures e.g., threads

More information

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: concurrency

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: concurrency Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: concurrency Outline Java threads thread implementation sleep, interrupt, and join threads that return values Thread synchronization

More information

Java Threads. Written by John Bell for CS 342, Spring 2018

Java Threads. Written by John Bell for CS 342, Spring 2018 Java Threads Written by John Bell for CS 342, Spring 2018 Based on chapter 9 of Learning Java, Fourth Edition by Niemeyer and Leuck, and other sources. Processes A process is an instance of a running program.

More information

The New Java Technology Memory Model

The New Java Technology Memory Model The New Java Technology Memory Model java.sun.com/javaone/sf Jeremy Manson and William Pugh http://www.cs.umd.edu/~pugh 1 Audience Assume you are familiar with basics of Java technology-based threads (

More information

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst Operating Systems CMPSCI 377 Spring 2017 Mark Corner University of Massachusetts Amherst What is a Monitor? Ties data and the synchronization operations together Monitors guarantee mutual exclusion, i.e.,

More information

What is a thread anyway?

What is a thread anyway? Concurrency in Java What is a thread anyway? Smallest sequence of instructions that can be managed independently by a scheduler There can be multiple threads within a process Threads can execute concurrently

More information

Program Graph. Lecture 25: Parallelism & Concurrency. Performance. What does it mean?

Program Graph. Lecture 25: Parallelism & Concurrency. Performance. What does it mean? Program Graph Lecture 25: Parallelism & Concurrency CS 62 Fall 2015 Kim Bruce & Michael Bannister Some slides based on those from Dan Grossman, U. of Washington Program using fork and join can be seen

More information

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit Threads Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multitasking Thread-based multitasking Multitasking

More information

Parallel Programming: Background Information

Parallel Programming: Background Information 1 Parallel Programming: Background Information Mike Bailey mjb@cs.oregonstate.edu parallel.background.pptx Three Reasons to Study Parallel Programming 2 1. Increase performance: do more work in the same

More information

Parallel Programming: Background Information

Parallel Programming: Background Information 1 Parallel Programming: Background Information Mike Bailey mjb@cs.oregonstate.edu parallel.background.pptx Three Reasons to Study Parallel Programming 2 1. Increase performance: do more work in the same

More information

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07 Informatica 3 Marcello Restelli 9/15/07 10/29/07 Laurea in Ingegneria Informatica Politecnico di Milano Structuring the Computation Control flow can be obtained through control structure at instruction

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Multithreading Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to large compute clusters Can perform multiple

More information

Part I: Communication and Networking

Part I: Communication and Networking Review what we learned Part I: Communication and Networking Communication and Networking: Week 5-6, Lectures 2-7 Lecture 1 OSI vs TCP/IP model OSI model Protocols TCP/IP model Application FTP SMTP HTTP

More information

Concurrency in Java Prof. Stephen A. Edwards

Concurrency in Java Prof. Stephen A. Edwards Concurrency in Java Prof. Stephen A. Edwards The Java Language Developed by James Gosling et al. at Sun Microsystems in the early 1990s Originally called Oak, first intended application was as an OS for

More information

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski Operating Systems Design Fall 2010 Exam 1 Review Paul Krzyzanowski pxk@cs.rutgers.edu 1 Question 1 To a programmer, a system call looks just like a function call. Explain the difference in the underlying

More information

Concurrent & Distributed Systems Supervision Exercises

Concurrent & Distributed Systems Supervision Exercises Concurrent & Distributed Systems Supervision Exercises Stephen Kell Stephen.Kell@cl.cam.ac.uk November 9, 2009 These exercises are intended to cover all the main points of understanding in the lecture

More information

Quiz on Tuesday April 13. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4. Java facts and questions. Things to try in Java

Quiz on Tuesday April 13. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4. Java facts and questions. Things to try in Java CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce

More information

Monitors; Software Transactional Memory

Monitors; Software Transactional Memory Monitors; Software Transactional Memory Parallel and Distributed Computing Department of Computer Science and Engineering (DEI) Instituto Superior Técnico March 17, 2016 CPD (DEI / IST) Parallel and Distributed

More information

Multithreading and Interactive Programs

Multithreading and Interactive Programs Multithreading and Interactive Programs CS160: User Interfaces John Canny. Last time Model-View-Controller Break up a component into Model of the data supporting the App View determining the look of the

More information

Synchronization in Java

Synchronization in Java Synchronization in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park Synchronization Overview Unsufficient atomicity Data races Locks Deadlock Wait /

More information

Multiple Inheritance. Computer object can be viewed as

Multiple Inheritance. Computer object can be viewed as Multiple Inheritance We have seen that a class may be derived from a given parent class. It is sometimes useful to allow a class to be derived from more than one parent, inheriting members of all parents.

More information

Object Oriented Programming and Design in Java. Session 21 Instructor: Bert Huang

Object Oriented Programming and Design in Java. Session 21 Instructor: Bert Huang Object Oriented Programming and Design in Java Session 21 Instructor: Bert Huang Announcements Homework 4 due now Homework 5 out now. Due last day of class: Mon. May 3rd Mon. May 3rd: Final review Mon.

More information

Concurrent Processes Rab Nawaz Jadoon

Concurrent Processes Rab Nawaz Jadoon Concurrent Processes Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS Lahore Pakistan Operating System Concepts Concurrent Processes If more than one threads

More information

POSIX Threads: a first step toward parallel programming. George Bosilca

POSIX Threads: a first step toward parallel programming. George Bosilca POSIX Threads: a first step toward parallel programming George Bosilca bosilca@icl.utk.edu Process vs. Thread A process is a collection of virtual memory space, code, data, and system resources. A thread

More information

Threads Tuesday, September 28, :37 AM

Threads Tuesday, September 28, :37 AM Threads_and_fabrics Page 1 Threads Tuesday, September 28, 2004 10:37 AM Threads A process includes an execution context containing Memory map PC and register values. Switching between memory maps can take

More information

Concurrent Programming using Threads

Concurrent Programming using Threads Concurrent Programming using Threads Threads are a control mechanism that enable you to write concurrent programs. You can think of a thread in an object-oriented language as a special kind of system object

More information

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2004 Lecture 8: Semaphores, Monitors, & Condition Variables 8.0 Main Points: Definition of semaphores Example of use

More information

What is a Thread? Why Multicore? What is a Thread? But a fast computer runs hot THREADS AND CONCURRENCY. Concurrency (aka Multitasking)

What is a Thread? Why Multicore? What is a Thread? But a fast computer runs hot THREADS AND CONCURRENCY. Concurrency (aka Multitasking) What is a Thread? 2 THREADS AND CONCURRENCY A separate process that can perform a computational task independently and concurrently with other threads Most programs have only one thread GUIs have a separate

More information

Synchronization 1. Synchronization

Synchronization 1. Synchronization Synchronization 1 Synchronization key concepts critical sections, mutual exclusion, test-and-set, spinlocks, blocking and blocking locks, semaphores, condition variables, deadlocks reading Three Easy Pieces:

More information

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018 Deadlock and Monitors CS439: Principles of Computer Systems September 24, 2018 Bringing It All Together Processes Abstraction for protection Define address space Threads Share (and communicate) through

More information

CMSC 433 Programming Language Technologies and Paradigms. Concurrency

CMSC 433 Programming Language Technologies and Paradigms. Concurrency CMSC 433 Programming Language Technologies and Paradigms Concurrency What is Concurrency? Simple definition Sequential programs have one thread of control Concurrent programs have many Concurrency vs.

More information