Synchronization and liveness

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Practice Session 7 Synchronization Liveness Deadlock Starvation Livelock Guarded Methods Model Thread Timing Busy Wait Sleep and Check Wait and Notify.
Synchronization and Deadlocks
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
EEE 435 Principles of Operating Systems Interprocess Communication Pt II (Modern Operating Systems 2.3)
Monitors & Blocking Synchronization 1. Producers & Consumers Problem Two threads that communicate through a shared FIFO queue. These two threads can’t.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
Practice Session 7 Synchronization Liveness Guarded Methods Model
SPL/2010 Liveness And Performance 1. SPL/2010 Performance ● Throughput - How much work can your program complete in a given time unit? ● Example: HTTP.
Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Threading Part 4 CS221 – 4/27/09. The Final Date: 5/7 Time: 6pm Duration: 1hr 50mins Location: EPS 103 Bring: 1 sheet of paper, filled both sides with.
Concurrency, Race Conditions, Mutual Exclusion, Semaphores, Monitors, Deadlocks Chapters 2 and 6 Tanenbaum’s Modern OS.
Semaphores. Announcements No CS 415 Section this Friday Tom Roeder will hold office hours Homework 2 is due today.
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.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
1 CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 19 th, 2010 The University of Georgia.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Race condition The scourge of parallel and distributed computing...
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
Kernel Locking Techniques by Robert Love presented by Scott Price.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
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.
COSC 3407: Operating Systems Lecture 9: Readers-Writers and Language Support for Synchronization.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
CSC CSC 143 Threads. CSC Introducing Threads  A thread is a flow of control within a program  A piece of code that runs on its own. The.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Software Design 13.1 From controller to threads l Threads are lightweight processes (what’s a process?)  Threads are part of a single program, share state.
CSE 451 Section 4. 2 Synchronization High-level Monitors Java synchronized method OS-level support Special variables – mutex, semaphor, condition var.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Java.util.concurrent package. concurrency utilities packages provide a powerful, extensible framework of high-performance threading utilities such as.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Deadlock and Starvation
Interprocess Communication Race Conditions
Multithreading / Concurrency
Multi Threading.
Concurrency: Deadlock and Starvation
Process Synchronization: Semaphores
Background on the need for Synchronization
Synchronization Lecture 23 – Fall 2017.
Designing Parallel Algorithms (Synchronization)
Lecture 14: Pthreads Mutex and Condition Variables
Semaphore Originally called P() and V() wait (S) { while S <= 0
Liveness And Performance
Producer-Consumer Problem
Multithreading.
Lecture 2 Part 2 Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
Lecture 9 Synchronization.
Lecture 14: Pthreads Mutex and Condition Variables
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
NETWORK PROGRAMMING CNET 441
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
“The Little Book on Semaphores” Allen B. Downey
EECE.4810/EECE.5730 Operating Systems
Software Engineering and Architecture
More concurrency issues
Presentation transcript:

Synchronization and liveness SPL – PS7 Synchronization and liveness

Overview Locking and synchronization Atomic actions Guarded methods Concurrency states Producers-consumers pattern and blocking queues.

Locking/ Synchronization Sometimes we want to allow concurrent access to a resource which isn’t read only. Locking is a means of achieving consistent data. Only one thread can access a locked section each time. Locking in Java is done using the “synchronized” keyword.

Synchronization (cont) We can synchronize on a specific lock. When “synchronized” appears in the signature of the function, the lock used is “this”

Atomic operations Operations that appear to the rest of the system as if they occur at once. Java provides high level interface for atomic operations in Java’s Atomic library.

Atomic operations (cont) The increment and get method is implemented as follows in Java 8 The comareAndSet action is atomic in Java. It checks whether the value of current is equal to the value of the variable, and if so, sets the variable.

Guarded methods The guarded methods model delays the execution of a thread until a condition is satisfied. There are several approaches for checking if the condition is satisfied. We’ll show an example.

Busy waiting (a.k.a spinning) Each thread constantly checks whether the condition is met. Appropriate in very specific cases, in which the expected waiting time is very short, and we want to react with no delay.

Sleep & Check Similar to busy waiting, but the thread sleeps for an amount of time between each checking. Less wasteful of CPU resources. Introduces a delay in the reaction time of the thread.

Wait & Notify Supports communication between threads. A thread voluntarily waits for a specific event to occur. Another thread can notify the waiting thread. Supported in Java

Blocking queues A blocking queue is a queue that blocks a caller if it tries to put an element into a full queue, or take an element from an empty queue. The Java API contains an interface for blocking queue. We’ll show an implementation of a blocking queue with wait() and notifyAll()

Producers Consumers problem. The producers-consumers problem deals with the situation in which several producers generate some kind of product, and several consumers consume those products. A producer should block if the queue is full. A consumer should block if the queue is empty. We’ll show a solution for the problem with Java’s blocking queue.

Liveness A concurrent application’s ability to execute in a timely manner is known as it’s liveness. There are several liveness problems, we’ll go over some of them in this practical session.

Deadlock A situation in which two or more threads are blocked, waiting for each other forever. Can be solved by resource ordering.

Starvation Describes a situation in which a thread is unable to gain regular access to a shared resource. Can happen when a shared resource is being held for a long period of time by a “greedy” thread. Can also happen when using priority scheduling. Can be solved by introducing fairness to the allocation of the shared resource. In Java, can be done using fair semaphores.

Livelock Two threads are unable to make further progress – like in a deadlock. Unlike deadlock, the threads are not blocked – they are too busy responding to each other to resume work.