Parallelism and Concurrency. Motivation, Challenges, Impact on Software Development CSE 110 Winter 2016

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

Deadlock and Monitors. CS439: Principles of Computer Systems February 7, 2018

Operating Systems. Thread Synchronization Primitives. Thomas Ropars.

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

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

Dealing with Issues for Interprocess Communication

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

CSE 153 Design of Operating Systems

Deadlock. Concurrency: Deadlock and Starvation. Reusable Resources

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4

Last Class: Monitors. Real-world Examples

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

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

CS-537: Midterm Exam (Spring 2001)

Process Management And Synchronization

Concurrency Issues. Past lectures: What about coordinated access across multiple objects? Today s lecture:

Condition Variables CS 241. Prof. Brighten Godfrey. March 16, University of Illinois

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

CS 220: Introduction to Parallel Computing. Introduction to CUDA. Lecture 28

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

CSE 153 Design of Operating Systems

Concurrent Processes Rab Nawaz Jadoon

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

Deadlock CS 241. March 19, University of Illinois

Concurrency. Glossary

CS 153 Design of Operating Systems Winter 2016

Concurrency: Principles of Deadlock. Processes and resources. Concurrency and deadlocks. Operating Systems Fall Processes need resources to run

CSE 153 Design of Operating Systems

CS370 Operating Systems

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

Last Class: Deadlocks. Where we are in the course

What's wrong with Semaphores?

Operating systems and concurrency (B08)

Lecture 8: September 30

CS 153 Design of Operating Systems Winter 2016

Concurrency: Mutual Exclusion (Locks)

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Chapter 5: Synchronization 1

Deadlock. Disclaimer: some slides are adopted from Dr. Kulkarni s and book authors slides with permission 1

Lecture 9: Midterm Review

Synchronization 1. Synchronization

CSE 120. Summer, Inter-Process Communication (IPC) Day 3. Inter-Process Communication (IPC) Scheduling Deadlock. Instructor: Neil Rhodes

The Deadlock Lecture

Process Synchronization - I

High Performance Computing Lecture 21. Matthew Jacob Indian Institute of Science

Last Class: Synchronization Problems. Need to hold multiple resources to perform task. CS377: Operating Systems. Real-world Examples

CSL373: Lecture 5 Deadlocks (no process runnable) + Scheduling (> 1 process runnable)

Deadlocks: Detection & Avoidance

Introduction to Concurrency (Processes, Threads, Interrupts, etc.)

Synchronization COMPSCI 386

IT 540 Operating Systems ECE519 Advanced Operating Systems

Operating Systems. Synchronization

Multiprocessor Systems. Chapter 8, 8.1

CSE 120 Principles of Operating Systems Spring 2016

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

Midterm Exam #2 Solutions October 25, 2016 CS162 Operating Systems

Midterm Exam. October 20th, Thursday NSC

Operating Systems ECE344

Synchronization in Concurrent Programming. Amit Gupta

Consistency. CS 475, Spring 2018 Concurrent & Distributed Systems

Introduction to Operating Systems

Consistency: Strict & Sequential. SWE 622, Spring 2017 Distributed Software Engineering

Chapter 5 Asynchronous Concurrent Execution

Opera&ng Systems ECE344

Computer Science 4500 Operating Systems. In This Module. Deadlock Definition. Module 7 Deadlocks

Computer Science 4500 Operating Systems

Resource management. Real-Time Systems. Resource management. Resource management

CS 318 Principles of Operating Systems

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Lecture 28 Multicore, Multithread" Suggested reading:" (H&P Chapter 7.4)"

Agenda. Highlight issues with multi threaded programming Introduce thread synchronization primitives Introduce thread safe collections

Concurrency, Thread. Dongkun Shin, SKKU

Notes to Instructors Concerning the BLITZ Projects

Let s go straight to some code to show how to fire off a function that runs in a separate thread:

Threads, Synchronization, and Scheduling. Eric Wu

CS 537 Lecture 11 Locks

CS533 Concepts of Operating Systems. Jonathan Walpole

Page 1. Goals for Today" Atomic Read-Modify-Write instructions" Examples of Read-Modify-Write "

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology

Concurrent & Distributed Systems Supervision Exercises

Classical Synchronization Problems. Copyright : University of Illinois CS 241 Staff 1

Deadlock Revisited. CS439: Principles of Computer Systems November 29, 2017

The mutual-exclusion problem involves making certain that two things don t happen at once. A non-computer example arose in the fighter aircraft of

Concurrency: Deadlock and Starvation. Chapter 6

Concurrency: Locks. Announcements

Interprocess Communication By: Kaushik Vaghani

CHAPTER 6: PROCESS SYNCHRONIZATION

Concurrent Programming Lecture 10

CSE 306/506 Operating Systems Deadlock. YoungMin Kwon

Synchronization Classic Problems

CS370 Operating Systems

Deadlocks Detection and Avoidance. Prof. Sirer CS 4410 Cornell University

CS 10: Problem solving via Object Oriented Programming Winter 2017

CS140 Operating Systems and Systems Programming Midterm Exam

Process Management. Deadlock. Process Synchronization. Management Management. Starvation

CS162 Operating Systems and Systems Programming Lecture 7 Semaphores, Conditional Variables, Deadlocks"

DUH! Deadlocks. Concurrency Issues. The TENEX Case. If a process requests all systems buffers, operator console tries to print an error message

Synchronization 1. Synchronization

Transcription:

Parallelism and Concurrency Motivation, Challenges, Impact on Software Development CSE 110 Winter 2016

About These Slides Due to the nature of this material, this lecture was delivered via the chalkboard. Every was advised that slides would not be available and that notes should be taken. These slides aren t designed to capture the discussion, just to provide some bullet points.

Parallelism vs Concurrency Parallelism: Running at the same time upon parallel resources Concurrency: Running at the same time, whether via parallelism or by turntaking, e.g. interleaved scheduling.

Parallelism Wasn t very prevalent until recently. Multi-processor systems were prevalent for servers and in scientific computing But, they weren t commonly used by end user devices, e.g. personal computers, etc. For many years, clock speed was the de facto measure of system performance and increased rapidly. In the mid-2000s we hit the end of Moore s law in some ways. Transistors became less limiting than connections Hot spots. Density limits

Multi-Core Became Standard Many cores on same die Many smaller chips less compolex than one big one Out of the box gains from multitasking different tasks on different cores Better for power management. Easier to save energy by turning off a core than by slowing one down Gains can be had by slowing down tractor-trailers. But, idling a tractor-trailer takes more energy than idling a car. Essentially the same idea Workstations, personal computer, phones, tablets, etc.

Bigger Gains When Software is Aware Imagine one huge task: Game, CAD, simulation, rendering, etc Not helped by multiple cores if it can only run on one at a time Modern world requires threading: Dividing big tasks into independent parts that can run at the same time on different core. Thread for each player in game, thread for scene, thread for communications, etc. This is as true on a high-performance workstation as phone.

Classic Concurrency Problem: Lost Update (0) x=0 (5,6) x=1 Memory (1)%eax=0 (4)%eax=1 (2) %eax=0 (3) %eax=1 Per-Thread Registers // x++ (1) mov addr,%eax (4) inc %eax (5) mov %eax, addr // x++ (2) mov addr,%eax (3) inc %eax (6) mov %eax, addr Code

Concurrency Problems Can occur as the result of actual parallelism Can occur just by interleaved execution Need a sharing discipline In other words, all interacting code needs to play nice with others

Critical Resources, Critical Sections Critical Resources: Shared resources, whether hardware or abstract, that can t naturally be shared in the intended way Toilets can t be shared. Variables can t be shared if written Sound can be shared. Air can be shared. Variables can be shared if only read. Critical Sections (of code): The code that manipulates the critical resources. This is the code that needs to be disciplined Common technique is some form of locking

One Classic Concurrency Solution: Some Form of Locking (0) x=0 (4) x=0 (9) x=1 Memory (1)%eax=0 (3)%eax=1 (6) %eax=1 (8) %eax=1 Per-Thread Registers // x++ (1) lock_aquire(x_lock) (2) mov addr,%eax (3) inc %eax (4) mov %eax, addr (5) loc_release(x_lock) // x++ (6) lock_aquire(x_lock) (7) mov addr,%eax (8) inc %eax (9) mov %eax, addr (10) loc_release(x_lock) Code

Concurrency Control Primitives You ll learn more in CSE 120 and/or CSE 160 Semaphores Mutexes Condition variables Etc

Higher-Level Constructs Monitor: A higher-level synchronization abstraction: Put related critical resources into a box, i.e. monitor. Only allow them to be accesses by the monitor s entry methods The abstraction is implemented using lower-level primitives to ensure that only one entry method can be active within the monitor at the same time Slightly different semantics are possible when complications, such as blocking (needing to wait for a resource outside of the monitor), are considered, e.g. Mesa semantics, Hoare semantics, etc. This level of detail is for another class.

Monitors In Java: Synchronized Methods Essentially turns an instance into a monitor Only one synchronized method can be active upon the instance at a time Just add synchronized qualifier to method that you want to discipline, e.g. synchronized void increment() Still things to watch Constructors cannot be synchronized Unsynchronized methods Also note: Java has many, many more ways of supporting concurrency control: Out of scope for this class

Properties of Good Solutions Mutual Exclusion: In many cases, critical resources can not be shared at all. In these cases we want to have mutual exclusion, i.e. the situation where the use by one thread of the critical resource excludes use by the other threads. In some cases, other policies, such as At Most N are appropriate, e.g. only N buffers exist. In these cases, we want to ensure whatever the constraint happens to be. Progress: If the critical resource is available, and a thread wants to use it, it should be able to do that. We don t want a situation where no one can use it Bounded Wait: It is often desirable to ensure that every thread will eventually get a turn. This is called bounded wait. This isn t always desirable, though. In some cases, we want a strict priority system, in which case, if there isn t enough resource time, some threads will starve. But, at the least, the more important things got done.

Deadlock: 4 Necessary and Sufficient Conditions Necessary: Deadlock can not occur without any one of these Sufficient: Deadlock will necessarily occur if all of these are true. The Necessary and Sufficient conditions for deadlock: Unsharable resource: If the resource can be shared, there is no reason to wait for it. Hold and wait : It is possible to hold some resources (denying them to other threads), while waiting for other resources, potentially held by other threads Circular wait: The hold and wait forms a cycle, so that it can never be resolved. No pre-emption: No way to take resources from thread holding them to break cycle.

Chopstick Example I have the left chopstick and need the right chopstick You have the right chopstick and need the left chopstick We both starve.

Deadlock Detection It is possible, but really involved and really intensive Once detected, there are usually no good options Can t really reach into code logic and change it Only real option is usually killing a thread, freeing its resources, breaking the cycle

Avoiding Deadlock Unsharable resource: We can t usually change the nature of the resource. Toilets aren t, for example, sharable Hold and wait: We might be able to require that all resources be allocated at once. But, this is very limiting. Consider branching in code. It would take resources off-line that would never be used, etc. We d also need to deal with contention for the basket. No-Premeption: We could do deadlock detection and then kill off one of the threads within a cycle. But, this can waste a lot of work (and annoy whoever the thread was serving) Circular wait: This is the one we usually manage. If we request resources in the same order, and there is no cycle in our ordering, there can be no circular dependency. It is more limiting than allowing resources to be requested in arbitrary order, but much more flexible than an all-at-once policy.

Chopstick Example: Fixed Everyone agrees to get left chopstick before right chopstick Now, whoever gets the left chopstick can get the right chopstick Whoever doesn t get the left chopstick will wait The user of the two chopsticks will finish, releasing them for later

Last Word Concurrent programming, once the domain only of those working in scientific computing, is now the domain of almost every programmer. It is important to explore and learn Some challenges and solutions can be really complex But, most situations are relatively straight-forward