Scalable lock-free Stack Algorithm Wael Yehia York University February 8, 2010.

Slides:



Advertisements
Similar presentations
Stacks.
Advertisements

Stacks, Queues, and Linked Lists
Scalable Flat-Combining Based Synchronous Queues Danny Hendler, Itai Incze, Nir Shavit and Moran Tzafrir Presentation by Uri Golani.
Stack & Queues COP 3502.
Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
CS252: Systems Programming Ninghui Li Program Interview Questions.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Scalable and Lock-Free Concurrent Dictionaries
0 of 37 Stacks and Queues Lecture of 37 Abstract Data Types To use a method, need to know its essentials: signature and return type o additionally,
Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Introduction to Lock-free Data-structures and algorithms Micah J Best May 14/09.
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Lecture 6 Feb 12 Goals: stacks Implementation of stack applications Postfix expression evaluation Convert infix to postfix.
CS510 Advanced OS Seminar Class 10 A Methodology for Implementing Highly Concurrent Data Objects by Maurice Herlihy.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
A Dynamic Elimination-Combining Stack Algorithm Gal Bar-Nissan, Danny Hendler and Adi Suissa Department of Computer Science, BGU, January 2011 Presnted.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
Stack and Queue.
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
Data Structures and Algorithms Stacks. Stacks are a special form of collection with LIFO semantics Two methods int push( Stack s, void *item ); - add.
Appendix E-A Hashing Modified. Chapter Scope Concept of hashing Hashing functions Collision handling – Open addressing – Buckets – Chaining Deletions.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
מרצה: יהודה אפק מגיש: ערן שרגיאן. OutlineOutline Quick reminder of the Stack structure. The Unbounded Lock-Free Stack. The Elimination Backoff Stack.
Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Data Structures Stacks and Queues Phil Tayco Slide version 1.0 Feb. 16, 2015.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
A Methodology for Creating Fast Wait-Free Data Structures Alex Koganand Erez Petrank Computer Science Technion, Israel.
Data Structures & Algorithms
CSS446 Spring 2014 Nan Wang.  To understand the implementation of linked lists and array lists  To analyze the efficiency of fundamental operations.
Wait-Free Multi-Word Compare- And-Swap using Greedy Helping and Grabbing Håkan Sundell PDPTA 2009.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
Stacks Nour El-Kadri CSI Stacks Software stacks are abstract data types (structures) similar to physical stacks, Plates Trays Books PEZ dispenser.
Futures, Scheduling, and Work Distribution Speaker: Eliran Shmila Based on chapter 16 from the book “The art of multiprocessor programming” by Maurice.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Concurrent Stacks Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
DECS: A Dynamic Elimination-Combining Stack Algorithm Gal Bar-Nissan, Danny Hendler, Adi Suissa 1 OPODIS 2011.
STACK Data Structure
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Distributed Algorithms (22903) Lecturer: Danny Hendler Lock-free stack algorithms.
Data Structures Intro2CS – week Stack ADT (Abstract Data Type) A container with 3 basic actions: – push(item) – pop() – is_empty() Semantics: –
Comprehensive Introduction to OOP with Java, C. Thomas Wu Stack ADT
Stacks and Queues Chapter 4.
CS 1114: Implementing Search
Data Structures and Algorithms
Stacks and Queues.
Stack and Queue APURBO DATTA.
Distributed Algorithms (22903)
Distributed Algorithms (22903)
A Lock-Free Algorithm for Concurrent Bags
Distributed Algorithms (22903)
COMPUTER 2430 Object Oriented Programming and Data Structures I
Pointers and Dynamic Variables
Distributed Algorithms (22903)
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
Data Structures and Algorithms
Scalable lock-free Stack Algorithm
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Model Checking of a lock-free stack
LAB#3 Stacks Nora Albabtin nora albabtin.
Stacks.
Presentation transcript:

Scalable lock-free Stack Algorithm Wael Yehia York University February 8, 2010

My Paper Danny Hendler, Nir Shavit, and Lena Yerushalmi. A scalable lock-free stack algorithm. In SPAA 2004: Proceedings of the Sixteenth Annual ACM Symposium on Parallel Algorithms, June 27-30, 2004, Barcelona, Spain, pages 206–215, Revised and published in Journal of Parallel and Distributed Computing, Volume 70, Issue 1, January 2010, Pages 1-12

Stacks A Stack is a Last In, First Out (LIFO) abstract data structure [Wikipedia] It can have any abstract data type as an element Provides two operations: – Pop(): removes and return the top element – Push(v): adds v to the top of the stack

Example of a stack after 3 pushes: push(1), push(5), push(2) A simple Sequential implementation top Stack{ Cell * top; } Cell{ Cell * next; int value; } 251 stack Cell

Push(3) Before: After: top stack top stack

Pop() Before: After: Return: top stack top stack cell

Intuitive lock-free shared stack Similar to sequential version But the top pointer is guarded by a CAS object. void push(E x){ head = stack.top; x.next = head; return CAS(stack.top, head, x); } E pop(){ head = stack.top; if(head == NULL) return EMPTY; next = head.next; if(CAS(stack.top, head, next)) return head; else return FAIL; } bool CAS(L, Old, New) { atomically { if (*L == Old) { *L = New; return true; } else return false; }

Problems with this approach High Memory contention on the CAS object at high loads Chances are, that many will fail, i.e. CAS(old,new) == false. Solution: use Elimination as a Backoff mechanism

Backoff mechanism An old technique used in various places such as packet- switching networks and ethernet Idea: spread the access to a busy location out in time. For our case: Instead of keep trying to modify the top pointer, spread the thread accesses out in time. Various ways to spread out: randomly, evenly, or based on traffic history Our approach is wait for a predefined time t 1 t 2 t 3 t 4 time Example of 4 threads t 1, t 2,t 3, and t 4 that collided and are spread in time randomly

Elimination technique Opposite operations such as push and pop eliminate their effect on the stack. Ex: push(1) followed by pop() keeps the stack in the same state. Every pair of push() and pop() can simply exchange data and terminate without ever touching the stack. Data exchange means the popping thread reads the pushed element from the pushing thread The problem is finding these pairs Stack initially After push(1) After pop() top

The new algorithm Combines backoff schemes and elimination: Each thread first tries to execute directly on the stack If it fails then it backs off and tries to find a partner thread with an opposite operation If elimination fails, it will wait for some time and retry on the stack, and so on. while(true){ if(performOpOnStack()) return; if(tryToCollide()) return; wait(sometime); }

Collision array Each thread need to find a partner to eliminate itself with use collision array A simple array of ids, of predefined length A thread picks a random location and write its id there Two threads collide if they choose same location. Collided threads check if they match and then eliminate by exchanging data Otherwise the elimination fails and they proceed to execute their ops on the stack

Example A system of 4 threads. Initial state of the stack and collision array: top EMPTY Stack Collision Array of length 2

3 Threads try to execute t 1 : push(3), t 2 : pop(), t 3 : push(1) All 3 threads fail to modify the top pointer So they try to collide: t1t1 t2t2 t3t3 backoff top Stack Collision Array

Elimination in progress t 2 and t 3 are suitable for elimination t 2 reads the value “1” from t 3 and both return; t 1 finds no partner, so waits, and goes to the stack t1t1 t2t2 t3t3 top wait return pop push(1)

Possible improvement and the next step Backing off for constant time is not always the best solution Dynamically resizing the collision array Next Step: –Implement the algorithm –Compare it to the java’s synchronized Stack