Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Scalable Flat-Combining Based Synchronous Queues Danny Hendler, Itai Incze, Nir Shavit and Moran Tzafrir Presentation by Uri Golani.
Wait-Free Queues with Multiple Enqueuers and Dequeuers
1 Chapter 4 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2014 Synchronization Algorithms and Concurrent Programming Synchronization.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
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)
Maged M. Michael, “Hazard Pointers: Safe Memory Reclamation for Lock- Free Objects” Presentation Robert T. Bauer.
Monitors & Blocking Synchronization 1. Producers & Consumers Problem Two threads that communicate through a shared FIFO queue. These two threads can’t.
A Lock-Free Multiprocessor OS Kernel1 Henry Massalin and Calton Pu Columbia University June 1991 Presented by: Kenny Graunke.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Introduction to Lock-free Data-structures and algorithms Micah J Best May 14/09.
Simple, Fast, and Practical Non- Blocking and Blocking Concurrent Queue Algorithms Presenter: Jim Santmyer By: Maged M. Micheal Michael L. Scott Department.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CS510 Concurrent Systems Class 2 A Lock-Free Multiprocessor OS Kernel.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
שירן חליבה Concurrent Queues. Outline: Some definitions 3 queue implementations : A Bounded Partial Queue An Unbounded Total Queue An Unbounded Lock-Free.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
CS510 Concurrent Systems Introduction to Concurrency.
Stack and Queue.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
CS510 Concurrent Systems Jonathan Walpole. A Lock-Free Multiprocessor OS Kernel.
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
Producer-Consumer Problem The problem describes two processes, the producer and the consumer, who share a common, fixed-size buffer used as a queue.bufferqueue.
Maged M.Michael Michael L.Scott Department of Computer Science Univeristy of Rochester Presented by: Jun Miao.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
Kernel Locking Techniques by Robert Love presented by Scott Price.
11/21/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
SPL/2010 Guarded Methods and Waiting 1. SPL/2010 Reminder! ● Concurrency problem: asynchronous modifications to object states lead to failure of thread.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Software Systems Advanced Synchronization Emery Berger and Mark Corner University.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
Gal Milman Based on Chapter 10 (Concurrent Queues and the ABA Problem) in The Art of Multiprocessor Programming by Herlihy and Shavit Seminar 2 (236802)
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
November 27, 2007 Verification of a Concurrent Priority Queue Bart Verzijlenberg.
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects MAGED M. MICHAEL PRESENTED BY NURIT MOSCOVICI ADVANCED TOPICS IN CONCURRENT PROGRAMMING,
Scalable lock-free Stack Algorithm Wael Yehia York University February 8, 2010.
Semaphores Chapter 6. Semaphores are a simple, but successful and widely used, construct.
Concurrency: Locks and synchronization Slides by Prof. Cox.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
The Structuring of Systems Using Upcalls By David D. Clark Presented by Samuel Moffatt.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Review Array Array Elements Accessing array elements
Håkan Sundell Philippas Tsigas
Chapter 12: Data Structures
Stacks and Queues.
Queues Queues Queues.
Challenges in Concurrent Computing
A Lock-Free Algorithm for Concurrent Bags
CS510 Concurrent Systems Jonathan Walpole.
Anders Gidenstam Håkan Sundell Philippas Tsigas
Pointers and Linked Lists
CS510 Concurrent Systems Jonathan Walpole.
Lesson Objectives Aims
Race Conditions & Synchronization
Producer-Consumer Problem
Semaphores Chapter 6.
Model Checking of a lock-free stack
Chapter 7: Synchronization Examples
CS510 Concurrent Systems Jonathan Walpole.
Stacks, Queues, and Deques
EECE.4810/EECE.5730 Operating Systems
Synchronization and liveness
Presentation transcript:

Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg

Introduction Queues are a way for different threads to communicate and exchange information between them. In a thread-safe, concurrent and asynchronous queue, consumers typically wait for producers to make data available. In a synchronous queue, producers similarly wait for consumers to take the data – “a pair up”.

Hanson’s Synchronous Queue

Hanson’s Pros & Cons Pros High design-level tractability. Using semaphores to target wakeups to only the single producer or consumer thread that an operation has unblocked. Cons: May fall victim to priority inversion. Poor performance - employs three separate blocking semaphores (locks). Possible Solution? Use non blocking synchronization!

Java 5.0 synchronous queue The Java SE 5.0 synchronous queue (below) uses a pair of queues (in fair mode; stacks for unfair mode) to separately hold waiting producers and consumers.

Java 5.0 synchronous queue (Cont.)

Java 5 Version – Pros & Cons Pros Uses a pair of queues to separately hold waiting producers and consumers. Allows producers to publish data items as they arrive instead of having to first awaken after blocking on a semaphore; consumers need not wait. One transfer (put & take), requires only three synchronization operations, compared to the six incurred by Hanson’s. Cons: Relies on one lock to protect access to both queues – creates a narrow bottleneck during runtime.

Non-Blocking Synchronization Non blocking concurrent objects avoid mutual exclusion and locks. Instead, they use atomic CAS operations (compare & swap) to make sure object’s invariants still hold afterwards. Totalized operations: Operations that don't block and return a failure code in case the preconditions aren't met. Example: dequeing from an empty queue will not cause the thread to block, but to return a failure code instead.

Non-Blocking Synchronization (Cont.) What isn't promised to any thread in the following scenario when using totalized operations? So, how can we fix this?

Dual Data Structures We could register a request (reservation) for a hand-off partner. Reservation is made in non blocking manner. Reservation is fulfilled by checking whether a pointer has changed in the reservation. The structure may contain both data and reservations.

Dual Data Structures (Cont.) Totalized methods are now split into 2 partial methods: reserve and follow-up. Main advantage over totalized partial methods: Order of reservations is saved.

Main Properties The algorithms I will present will be: Contention free. Lock free. Scalable. Fair & unfair implementations. Have solid linearization points. Waiting is done by spinning, busy waiting.

Synchronous Dual Queue Fair implementation. A linked list with a head & tail. Waiting is accomplished by spinning until a pointer changes from null to non-null. If not empty, has always a dummy node at the beginning while other nodes are always of the same type: reservation or data. Dequeue & enqueue are symmetrical except for the direction of the data flow. Let’s take a look at the enqueue operation.

Synchronous Dual Queue (Cont.) First case: Queue is empty or contains only data. Add a new data node at the end of the queue and spin. Second case (interesting): Q ueue contains only reservation.

First case code:

Synchronous Dual Queue (Cont.) Second case code:

Synchronous Dual Stack A singly linked list with only a head node. Not fair. Doesn’t have a dummy node at the beginning. May contain either data or reservation nods but also temporarily a single node of the opposite type at the head. Push& pop are symmetrical except for the direction of the data flow. Let’s take a look at the push operation.

Synchronous Dual Stack (Cont.) First case: Stack is empty or contains only data. Add a new data node at the head of the stack and spin. Second case (interesting): Stack contains reservation at the head. Add a new data (“fulfilling”) node at the head, find a reservation to fulfill and remove both nodes. Third case: A fulfilling node at the head. Help the fulfillment process.

First case code:

Second case code:

Third case code:

Results

Results (Cont.)

Conclusion I presented 2 non blocking synchronous queues that use dual data structures: a fair and unfair version (stack & queue). The algorithms are all lock-free. There is little performance cost for fairness. High scalability can be achieved by using synchronization methods that don’t use locks. The Algorithms are part of the Java 6 packages.