1 Based on: The art of multiprocessor programming Maurice Herlihy and Nir Shavit, 2008 Appendix A – Software Basics Appendix B – Hardware Basics Introduction.

Slides:



Advertisements
Similar presentations
Introduction Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit TexPoint fonts used in EMF. Read the TexPoint manual.
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Multiprocessors and Multithreading – classroom slides.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Mutual Exclusion The Art of Multiprocessor Programming Spring 2007.
Multiprocessor Architecture Basics The Art of Multiprocessor Programming Spring 2007.
Monitors & Blocking Synchronization 1. Producers & Consumers Problem Two threads that communicate through a shared FIFO queue. These two threads can’t.
Introduction Companion slides for
Spin Locks and Contention Based on slides by by Maurice Herlihy & Nir Shavit Tomer Gurevich.
Transactional Memory: Architectural Support for Lock- Free Data Structures Herlihy & Moss Presented by Robert T. Bauer.
COS 461 Fall 1997 Concurrent Programming u Traditional programs do one thing at a time. u Concurrent programs do several things at once. u Why do this?
Chapter 7 Threads  Threads & Processes  Multi Threading  Class Thread  Synchronized Methods  Wait & Notify.
1 Multiprocessors. 2 Idea: create powerful computers by connecting many smaller ones good news: works for timesharing (better than supercomputer) bad.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
1 Lecture 1: Parallel Architecture Intro Course organization:  ~5 lectures based on Culler-Singh textbook  ~5 lectures based on Larus-Rajwar textbook.
Chapter Hardwired vs Microprogrammed Control Multithreading
Introduction Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Rajeev Alur for CIS 640 at Penn, Spring.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
1 CSE SUNY New Paltz Chapter Nine Multiprocessors.
CS510 Concurrent Systems Class 5 Threads Cannot Be Implemented As a Library.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
CS510 Concurrent Systems Introduction to Concurrency.
Multiprocessors and Multi-computers Multi-computers –Distributed address space accessible by local processors –Requires message passing –Programming tends.
Multiprocessor Architecture Basics Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Ahmed Khademzadeh Azad University.
Multi-core systems System Architecture COMP25212 Daniel Goodman Advanced Processor Technologies Group.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
1 Concurrent Languages – Part 1 COMP 640 Programming Languages.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Shared Memory Consistency Models. SMP systems support shared memory abstraction: all processors see the whole memory and can perform memory operations.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Multiprocessor Cache Consistency (or, what does volatile mean?) Andrew Whitaker CSE451.
Fundamentals of Parallel Computer Architecture - Chapter 71 Chapter 7 Introduction to Shared Memory Multiprocessors Yan Solihin Copyright.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Programming Language Basics Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Multiprocessor Architecture Basics Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Techniques and Structures in Concurrent Programming Wilfredo Velazquez.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
August 13, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 11: Multiprocessors: Uniform Memory Access * Jeremy R. Johnson Monday,
Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Queue Locks and Local Spinning Some Slides based on: The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
SMP Basics KeyStone Training Multicore Applications Literature Number: SPRPxxx 1.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
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.
The University of Adelaide, School of Computer Science
Scalable Computing model : Lock free protocol By Peeyush Agrawal 2010MCS3469 Guided By Dr. Kolin Paul.
Concurrency Idea. 2 Concurrency idea Challenge –Print primes from 1 to Given –Ten-processor multiprocessor –One thread per processor Goal –Get ten-fold.
© 2010 IBM Corporation Concurrency Demystified Ajith Ramanath | Senior Developer | JTC-ISL.
Tutorial 2: Homework 1 and Project 1
Software Coherence Management on Non-Coherent-Cache Multicores
Multithreaded Programming in Java
Introduction to Concurrency: Hardware & Software
CMPT 886: Computer Architecture Primer
Symmetric Multiprocessing (SMP)
Synchronization Issues
Concurrency: Mutual Exclusion and Process Synchronization
Problems with Locks Andrew Whitaker CSE451.
Presentation transcript:

1 Based on: The art of multiprocessor programming Maurice Herlihy and Nir Shavit, 2008 Appendix A – Software Basics Appendix B – Hardware Basics Introduction to Concurrent Programming Software & Hardware Basics Slides by Ofer Givoli

Software Basics 2

3 Threads in Java Executes a single, sequential program Subclass of: java.lang.Thread

4 … Taken from: The art of multiprocessor programming, by Maurice Herlihy and Nir Shavit, 2008 (modified)

5 Monitors lock + waiting set every object is a monitor Critical section: using the synchronized keyword. Waiting: using the wait() method Waking-up waiting threads, using the methods: notify() notifyAll()

6 public class ConcurrentStack { private Stack innerStack = new Stack (); public void push(T obj) { innerStack.push(obj); } public T pop() { return innerStack.pop(); } } ConcurrentStack s =... s.push(1);... = s.pop(); Solution: mutual exclusion 

7... = s.pop(); public class ConcurrentStack { private Stack innerStack = new Stack (); private Object monitor = new Object(); public void push(T obj) { synchronized(monitor) { innerStack.push(obj); } } public T pop() { synchronized(monitor) { return innerStack.pop(); } } } BLOCKED

8 public class ConcurrentStack { private Stack innerStack = new Stack (); private Object monitor = new Object(); public void push(T obj) { synchronized(monitor) { innerStack.push(obj); } } public T pop() { synchronized(monitor) { return innerStack.pop(); } } }

9 public class ConcurrentStack { private Stack innerStack = new Stack (); public void push(T obj) { synchronized(this) { innerStack.push(obj); } } public T pop() { synchronized(this) { return innerStack.pop(); } } }

10 public class ConcurrentStack { private Stack innerStack = new Stack (); public synchronized void push(T obj) { innerStack.push(obj); } public synchronized T pop() { return innerStack.pop(); } } New feature: waiting for pop()

11 public class ConcurrentStack { private Stack innerStack = new Stack (); public synchronized void push(T obj) { innerStack.push(obj); } public synchronized T pop() { while (innerStack.empty()) {} return innerStack.pop(); } } Problem?

12... = s.pop(); public class ConcurrentStack { private Stack innerStack = new Stack (); public synchronized void push(T obj) { innerStack.push(obj); } public synchronized T pop() { while (innerStack.empty()) {} return innerStack.pop(); } } s.push(1); BLOCKED  deadlock

13 public class ConcurrentStack { private Stack innerStack = new Stack (); public synchronized void push(T obj) { innerStack.push(obj); } public synchronized T pop() { while (innerStack.empty()) {} return innerStack.pop(); } }

14 public class ConcurrentStack { private Stack innerStack = new Stack (); public synchronized void push(T obj) { if (innerStack.empty()) notifyAll(); innerStack.push(obj); } public synchronized T pop() { while (innerStack.empty()) {wait();} return innerStack.pop(); } }

... = s.pop();s.push(1); BLOCKED 15 WAITING public class ConcurrentStack { private Stack innerStack = new Stack (); public synchronized void push(T obj) { if (innerStack.empty()) notifyAll(); innerStack.push(obj); } public synchronized T pop() { while (innerStack.empty()) {wait();} return innerStack.pop(); } } BLOCKED

... = s.pop(); WAITING... = s.pop(); WAITING 16 public class ConcurrentStack { private Stack innerStack = new Stack (); public synchronized void push(T obj) { if (innerStack.empty()) notify(); innerStack.push(obj); } public synchronized T pop() { while (innerStack.empty()) {wait();} return innerStack.pop(); } } s.push(1); s.push(2);  lost wakeup

17 Thread.yield(); Thread.sleep(t);

18 Thread-Local Objects class ThreadLocallD extends ThreadLocal { protected Integer initialValue() { return …; } } ThreadLocallD id = …; id.set(…); … … = id.get(); id.set(…); … … = id.get();

19 Synchronization in C# Pthreads

Hardware Basics 20

21 Taken from:

22 L1 Cache Speed: Fastest Slowest Size: Smallest Biggest Cost: Highest Lowest Power: Highest Lowest CPU L2 Cache L3 Cache Memory (DRAM) Taken from: Computer Structure 2014 slides, by Lihu Rappoport and Adi Yoaz (modified)

23 Processor 1 L1 cache Processor 2 L1 cache L2 cache (shared) Memory Taken from: Computer Structure 2014 slides, by Lihu Rappoport and Adi Yoaz

24 SMP (symmetric multiprocessing) NUMA (Non-uniform memory access) Taken from: The art of multiprocessor programming, by Maurice Herlihy and Nir Shavit, 2008 (modified) not scalable

25 Cache Coherence Cache-line states: Modified Exclusive Shared Invalid Taken from: The art of multiprocessor programming, by Maurice Herlihy and Nir Shavit, 2008 (modified) false sharing

26 Spinning SMP NUMA Taken from: The art of multiprocessor programming, by Maurice Herlihy and Nir Shavit, 2008 (modified)

27 Execute instructions out-of-order/in parallel/speculatively. write buffer reordering of reads-writes by compiler memory barrier instruction (expensive) reads-writes reorder in Java Volatile variables in Java Multi-Core and Multi-Threaded Architectures Taken from: The art of multiprocessor programming, by Maurice Herlihy and Nir Shavit, 2008 (modified)

28 Hardware Synchronization Instructions compare-and-swap/set (CAS) load-linked & store-conditional (LL/SC)

Thanks! 29