Concurrency (3) CSE 132. iClicker/WUTexter Question The following four numbers are in 8-bit 2’s complement form: 00000000101010100101010111111111 Which.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
– R 7 :: 1 – 0024 Spring 2010 Parallel Programming 0024 Recitation Week 7 Spring Semester 2010.
Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Ch 7 B.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Chapter 6: Process Synchronization
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
CS 5704 Fall 00 1 Monitors in Java Model and Examples.
Monitors Chapter 7. The semaphore is a low-level primitive because it is unstructured. If we were to build a large system using semaphores alone, the.
Assignment – no class Wednesday All: watch the Google Techtalk “Getting C++ Threads Right” by Hans Boehm at the following link in place of Wednesday’s.
Concurrency: Deadlock and Starvation Chapter 6. Revision Describe three necessary conditions for deadlock Which condition is the result of the three necessary.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other.
© Amir Kirsh Threads Written by Amir Kirsh. 2 Lesson’s Objectives By the end of this lesson you will: Be familiar with the Java threads syntax and API.
More Multithreaded Programming in Java David Meredith Aalborg University.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 19 th, 2010 The University of Georgia.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
Internet Software Development More stuff on Threads Paul Krause.
1 Java Threads and Synchronization Review Modified from slides taken from
Threads. Overview Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Internet Software Development Controlling Threads Paul J Krause.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
1 Program5 Due Friday, March Prog4 user_thread... amount = … invoke delegate transact (amount)... mainThread... Total + = amount … user_thread...
Kernel Locking Techniques by Robert Love presented by Scott Price.
Concurrency in Java Brad Vander Zanden. Processes and Threads Process: A self-contained execution environment Thread: Exists within a process and shares.
OPERATING SYSTEMS Frans Sanen.  Recap of threads in Java  Learn to think about synchronization problems in Java  Solve synchronization problems in.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
In Java processes are called threads. Additional threads are associated with objects. An application is associated with an initial thread via a static.
Java Thread and Memory Model
Threads Doing Several Things at Once. Threads n What are Threads? n Two Ways to Obtain a New Thread n The Lifecycle of a Thread n Four Kinds of Thread.
Dr. R R DOCSIT, Dr BAMU. Basic Java :Multi Threading Cont. 2 Objectives of This Session Explain Synchronization in threads Demonstrate use of.
SPL/2010 Guarded Methods and Waiting 1. SPL/2010 Reminder! ● Concurrency problem: asynchronous modifications to object states lead to failure of thread.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Multithreaded programming  Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
1 G53SRP: Java Concurrency Control (2) – wait/notify Chris Greenhalgh School of Computer Science.
3/17/2016cse synchronization-p2 © Perkins, DW Johnson and University of Washington1 Synchronization Part 2 CSE 410, Spring 2008 Computer.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Concurrency (2) CSE 132. Question The following four numbers are in 8-bit 2’s complement form: Which order below represents.
CS162 Section 2. True/False A thread needs to own a semaphore, meaning the thread has called semaphore.P(), before it can call semaphore.V() False: Any.
Java Thread Programming
Multithreading / Concurrency
Multi Threading.
Background on the need for Synchronization
Monitors Chapter 7.
Multithreading.
Multithreading.
Critical section problem
Programming with Shared Memory Java Threads and Synchronization
Programming with Shared Memory Java Threads and Synchronization
Another Means Of Thread Synchronization
Monitors Chapter 7.
Monitors Chapter 7.
Thread Synchronization including Mutual Exclusion
Kernel Synchronization II
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Software Engineering and Architecture
Presentation transcript:

Concurrency (3) CSE 132

iClicker/WUTexter Question The following four numbers are in 8-bit 2’s complement form: Which order below represents lowest to highest? A: B: C: D: E: none of the above

Synchronization Review Implicit “lock” associated with every object Synchronized methods acquire object’s lock prior to entering method and then release lock once method is complete Synchronized statement allows finer control (illustrated next) Either way, lock enforces mutual exclusion, only one thread at a time is allowed in “critical section,” or region of code controlled by lock

Synchronized statement public void addName(String name) { synchronized(this) { lastName = name; nameCount++; } nameList.add(name); } Argument is object whose lock is acquired Doesn’t synchronize add() method invocation Statements within synchronized block are “atomic”

Separating acquire and release Sync interface Mutex class Three methods: – void acquire() Wait until lock is available – boolean attempt(long msec) Wait until lock is available or until msec time passes – Void release() Release lock acquire() and release() need not be nearby to one another

Reader/Writer Locks Allow for more than one thread to have lock at the same time Only safe for read-only access Exclusive write – concurrent read Enforce only one of these statements to be true: – There are currently no readers or writers. – There is currently a positive number of readers but no writer. – There is currently exactly one writer but no readers.

Guards Wait until some other thread sets a value public void guardedJoy() { // Simple loop guard. Wastes // processor time. Don't do this! while(!joy) {} System.out.println("Joy has been achieved!"); }

Wait method public synchronized guardedJoy() { // This guard only loops once for each special event, // which may not be the event we're waiting for. while(!joy) { try { wait(); } catch (InterruptedException e) {} } System.out.println("Joy and efficiency have been achieved!"); } wait() releases control until an “event” occurs

Use of wait() Must own lock on object before invoking wait() NOTE: guardedJoy() is synchronized! When wait() is invoked, lock is released and thread is suspended (i.e., not executing), waiting for events Upon event notification, thread is awakened and wait() returns (with the lock)

Waking up Sleeping Threads Method notifyAll() public synchronized notifyJoy() { joy = true; notifyAll(); } Must own lock to invoke notifyAll() It knows nothing about joy! Put wait() in loop!

iClicker/WUTexter Question Which of the following statements is true? Note: One is true, and the rest are false A:An unchecked exception must have a try…catch block B:The.start() method initiates threaded execution C:The.run() method initiates threaded execution D:A method declared synchronized may specify the object to be locked E:A synchronized block may specify a separate method to release a lock

Quiz 1 In lab Wednesday. Link to Quiz 1 (Google form) will be provided on class web page. Password will be provided in lab. Complete (by yourself!) before you leave lab on Wednesday.