© 2010 IBM Corporation Concurrency Demystified Ajith Ramanath | Senior Developer | JTC-ISL.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Part IV: Memory Management
50.003: Elements of Software Construction Week 6 Thread Safety and Synchronization.
Chapter 6: Process Synchronization
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
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.
Scalable and Lock-Free Concurrent Dictionaries
Wait-Free Reference Counting and Memory Management Håkan Sundell, Ph.D.
Concurrency 101 Shared state. Part 1: General Concepts 2.
Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg.
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.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
Introduction to Lock-free Data-structures and algorithms Micah J Best May 14/09.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Multithreading.
Week 9 Building blocks.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Parallel Programming Philippas Tsigas Chalmers University of Technology Computer Science and Engineering Department © Philippas Tsigas.
Simple Wait-Free Snapshots for Real-Time Systems with Sporadic Tasks Håkan Sundell Philippas Tsigas.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
4.1 Introduction to Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads.
A Consistency Framework for Iteration Operations in Concurrent Data Structures Yiannis Nikolakopoulos A. Gidenstam M. Papatriantafilou P. Tsigas Distributed.
Maged M.Michael Michael L.Scott Department of Computer Science Univeristy of Rochester Presented by: Jun Miao.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
Java Thread and Memory Model
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
CSC Multiprocessor Programming, Spring, 2012 Chapter 11 – Performance and Scalability Dr. Dale E. Parson, week 12.
CS510 Concurrent Systems Jonathan Walpole. RCU Usage in Linux.
1 Based on: The art of multiprocessor programming Maurice Herlihy and Nir Shavit, 2008 Appendix A – Software Basics Appendix B – Hardware Basics Introduction.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
4.1 Introduction to Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads.
Week 9, Class 3: Java’s Happens-Before Memory Model (Slides used and skipped in class) SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a.
3/17/2016cse synchronization-p2 © Perkins, DW Johnson and University of Washington1 Synchronization Part 2 CSE 410, Spring 2008 Computer.
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.
@gfraiteur a deep investigation on how.NET multithreading primitives map to hardware and Windows Kernel You Thought You Understood Multithreading Gaël.
Background on the need for Synchronization
Processes and Threads Processes and their scheduling
Håkan Sundell Philippas Tsigas
Section 10: Last section! Final review.
Definitions Concurrent program – Program that executes multiple instructions at the same time. Process – An executing program (the running JVM for Java.
CS703 - Advanced Operating Systems
Midterm review: closed book multiple choice chapters 1 to 9
Lecture 2 Part 2 Process Synchronization
Chapter 7: Synchronization Examples
Real Time Java : Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
Operating Systems Lecture 1.
Concurrency, Processes and Threads
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
Chapter 6: Synchronization Tools
CSE 153 Design of Operating Systems Winter 2019
Operating Systems Concepts
CSC Multiprocessor Programming, Spring, 2011
Chapter 3: Process Management
Presentation transcript:

© 2010 IBM Corporation Concurrency Demystified Ajith Ramanath | Senior Developer | JTC-ISL

© 2010 IBM Corporation 2 What’s in store today?  Thinking Performance & Scalability  Erstwhile Java Synchronization  Tools & Diagnostics  Java Memory Model  Concurrency & Non-Blocking Synchronization  Concurrent Building Blocks in Java  A Simple Concurrent Data-structure  Overview of Project Amino  References

© 2010 IBM Corporation 3 Thinking Performance & Scalability…  What are multi-core systems?  Scaling UP (⇑) vs. Scaling OUT (⇔)  What are scalable programs?  Relevance of scalable software

© 2010 IBM Corporation 4 Erstwhile Java Synchronization  Java “synchronized” keyword  Object specific “mutex”  Applies to class and instance Objects  2 or 3 Tier lock strategy  Java semaphore implementation  Public wait() and notify() / notifyAll() methods  Accessible from all Java classes and objects  JSE specification provides semaphore via ‘ java.lang.Object ’ class  Lock contention & ensuing problems  Reduced parallelism & lower CPU utilization  Increased thread context switch time

© 2010 IBM Corporation 5 JLM Report Tools: Java Lock Monitor (JLM)  JVMPI/TI agent for profiling Java monitor entry and exit  Free Download from SourceForgeSourceForge  Available on Linux and Windows (x86_64 && IA32)  Simple to use and Light-weight Java Virtual Machine (JVM)JPROF rtdriver Socket JVMPI Enable / Disable Events Request Events JVM callback Textual commands Reports / Errors

© 2010 IBM Corporation 6 Sample JLM Output

© 2010 IBM Corporation 7  Timer based profiler – works using sampling technique  Tracks CPU ticks and maps them to kernel / application modules  Useful to investigate CPU over/under-utilization  Pick tprof ‘first’ during performance analysis! Tools: tprof JIT module taking the maximum clock ticks

© 2010 IBM Corporation 8 Java Memory Model  Java goofed up…before v5.0:  The ugly DCL paradigm ( A popular anti-pattern in Java!  )  (Im?)mutability  Compiler re-ordering / volatiles & non-volatile stores Immutability ProblemProblem with volatile/non-volatile storesDouble-checked Locking

© 2010 IBM Corporation 9 Concurrent Computing (to the rescue…) Definitions: Concurrent computing is a form of computing in which programs are designed as collections of interacting computational processes that may be executed in parallel A non-blocking algorithm ensures that threads competing for a shared resource do not have their execution indefinitely postponed by mutual exclusion.

© 2010 IBM Corporation10 Concurrent Building Blocks (CBBs) in Java  Atomic variables  Reentrant locks  Collection APIs  Semaphores  Latches  Cyclic Barriers  Future Semantics  Executors  Exchangers Since Java 50 (TIGER) release

© 2010 IBM Corporation11 Java Collection CBBs (A closer look…)  Queue Implementations:  BlockingQueue  Deque  ConcurrentLinkedQueue  Map Implementations:  ConcurrentHashMap  ConcurrentSkipListMap (since Java 60)  Set Implementations:  CopyOnWriteArraySet  ConcurrentSkipListSet (since Java 60)  List Implementations:  CopyOnWriteArrayList

© 2010 IBM Corporation12 A Simple Concurrent API (Treiber’s Algorithm) Class ConcurrentStack { static AtomicReference top = new AtomicReference (); public void push (Object item) { Node newHead = new Node(item); do { Node oldHead = top.get(); newHead.next = oldHead; } while (!top.compareAndSet(oldHead, newHead); } public Object pop() { Node newHead, oldHead; do { oldHead = top.get(); if (oldHead == null) return null; newHead = oldHead.next(); } while (!top.compareAndSet(oldHead, newHead); return oldHead.item; }

© 2010 IBM Corporation13 Project Amino  Building a scalable foundation for multicore programming  Multiplatform - Java and C++  Programming tools and libraries  Collaborative work between IBM research and IBM Software Labs  Available for download now on SouceForge  Open for your participation and contribution!

© 2010 IBM Corporation14 Amino Data Structures  Amino data- structures are designed to have lock-free or wait-free semantics  A lock-free operation allows optimistic concurrency, enables isolated thread failure and will not deadlock  A wait-free operation will always proceed without blocking  Focus on Java  Data structures complement Java’s JUC Stack Vector HashMap QueueDeque Dictionary Tree Priority Queue List Binary srch tree

© 2010 IBM Corporation15 References & Further Reading  Java Concurrency in Practice (by Brian Geotz – Pearson Education)  Oracle Java APIs Download siteOracle Java APIs Download site  High Performance Dynamic Lock-Free Hash Tables and List-Based SetsHigh Performance Dynamic Lock-Free Hash Tables and List-Based Sets  Scalable and Lock-Free Concurrent DictionariesScalable and Lock-Free Concurrent Dictionaries  Lock-free Dynamically Resizable ArraysLock-free Dynamically Resizable Arrays  Lock-free Resizable Hash TablesLock-free Resizable Hash Tables  Fast and Lock-Free Concurrent Priority Queues for Multi-Thread SystemsFast and Lock-Free Concurrent Priority Queues for Multi-Thread Systems  IBM DeveloperWorks series:  Java Theory and Practice: Fixing the Java Memory Model Part 1 and 2Part 12  Finally, use Wikipedia and Google Search Engine for more!

© 2010 IBM Corporation16 I’m done…are there (more?) questions?