Distributed Algorithms (22903)

Slides:



Advertisements
Similar presentations
Scalable Flat-Combining Based Synchronous Queues Danny Hendler, Itai Incze, Nir Shavit and Moran Tzafrir Presentation by Uri Golani.
Advertisements

IBM T. J. Watson Research Center Conditions for Strong Synchronization Maged Michael IBM T J Watson Research Center Joint work with: Martin Vechev, Hagit.
TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A AAA A A A AA A Proving that non-blocking algorithms don't block.
1 © R. Guerraoui The Power of Registers Prof R. Guerraoui Distributed Programming Laboratory.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
CPSC 668Set 18: Wait-Free Simulations Beyond Registers1 CPSC 668 Distributed Algorithms and Systems Fall 2006 Prof. Jennifer Welch.
Distributed Algorithms (22903) Lecturer: Danny Hendler Shared objects: linearizability, wait-freedom and simulations Most of this presentation is based.
Comparison Under Abstraction for Verifying Linearizability Daphna Amit Noam Rinetzky Mooly Sagiv Tom RepsEran Yahav Tel Aviv UniversityUniversity of Wisconsin.
A Dynamic Elimination-Combining Stack Algorithm Gal Bar-Nissan, Danny Hendler and Adi Suissa Department of Computer Science, BGU, January 2011 Presnted.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved. Who’s Afraid of a Big Bad Lock Nir Shavit Sun Labs at Oracle Joint work with Danny.
Parallel Programming Philippas Tsigas Chalmers University of Technology Computer Science and Engineering Department © Philippas Tsigas.
Linearizability By Mila Oren 1. Outline  Sequential and concurrent specifications.  Define linearizability (intuition and formal model).  Composability.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS Fall 2011 Prof. Jennifer Welch CSCE 668 Set 18: Wait-Free Simulations Beyond Registers 1.
1 CSE 1342 Programming Concepts Lists. 2 Basic Terminology A list is a finite sequence of zero or more elements. –For example, (1,3,5,7) is a list of.
מרצה: יהודה אפק מגיש: ערן שרגיאן. OutlineOutline Quick reminder of the Stack structure. The Unbounded Lock-Free Stack. The Elimination Backoff Stack.
Common2 extended to stacks and unbound concurrency By:Yehuda Afek Eli Gafni Adam Morrison May 2007 Presentor: Dima Liahovitsky 1.
CS510 Concurrent Systems Jonathan Walpole. A Methodology for Implementing Highly Concurrent Data Objects.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
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.
Distributed Algorithms (22903) Lecturer: Danny Hendler The wait-free hierarchy and the universality of consensus This presentation is based on the book.
DECS: A Dynamic Elimination-Combining Stack Algorithm Gal Bar-Nissan, Danny Hendler, Adi Suissa 1 OPODIS 2011.
Concurrent Computing Seminar Introductory Lecture Instructor: Danny Hendler
Scalable lock-free Stack Algorithm Wael Yehia York University February 8, 2010.
Distributed Algorithms (22903) Lecturer: Danny Hendler Shared objects: linearizability, wait-freedom and simulations Most of this presentation is based.
Distributed Algorithms (22903) Lecturer: Danny Hendler Lock-free stack algorithms.
Abstract Data Types and Stacks CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Last updated: 2/17/
Data Structures Intro2CS – week Stack ADT (Abstract Data Type) A container with 3 basic actions: – push(item) – pop() – is_empty() Semantics: –
Distributed Algorithms (22903)
STACKS & QUEUES for CLASS XII ( C++).
CSE 1342 Programming Concepts
Stacks II David Lillis School of Computer Science and Informatics
Review Array Array Elements Accessing array elements
Queues.
Lectures linked lists Chapter 6 of textbook
Concurrent Objects Companion slides for
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
Concurrent Objects Companion slides for
Distributed Algorithms (22903)
Distributed Algorithms (22903)
Data Structures – Week #3
A Lock-Free Algorithm for Concurrent Bags
Distributed Algorithms (22903)
Concurrent Objects.
Concurrent Objects Companion slides for
CMSC 341 Lecture 5 Stacks, Queues
Non-blocking data structures and transactional memory
Stacks.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Designing Parallel Algorithms (Synchronization)
Multicore programming
Distributed Algorithms (22903)
Distributed Algorithms (22903)
Scalable lock-free Stack Algorithm
Multicore programming
Abstract Data Types and Stacks
Model Checking of a lock-free stack
Multicore programming
Distributed Algorithms (22903)
CS333 Intro to Operating Systems
Using a Queue Chapter 8 introduces the queue data type.
Data Structures – Week #3
Using a Queue Chapter 8 introduces the queue data type.
Distributed Algorithms (22903)
Data Structures.
Nir Shavit Multiprocessor Synchronization Spring 2003
LINEAR DATA STRUCTURES
Abstract Data Types and Stacks
Presentation transcript:

Distributed Algorithms (22903) Lock-free stack algorithms Lecturer: Danny Hendler

Concurrent Objects Each object has a state Usually given by a set of shared memory fields Objects may be implemented from simpler base objects Each object supports a set of operations Only way to manipulate state E.g. – a shared counter supports the fetch&increment operation 3

Shared Objects Correctness Correctness of a sequential counter fetch&increment, applied to a counter with value v, returns v and increments the counter’s value to (v+1). Values returned by consecutive operations: 0, 1, 2, … But how shall we define the correctness of a shared counter?

Shared Objects Correctness (cont’d) Invocation Response fetch&inc q.enq(x) fetch&inc q.enq(y) fetch&inc q.deq(y) fetch&inc q.deq(x) time time There is only a partial order between operations!

Shared Objects Correctness (cont’d) A sequential object history is a sequence of matching invocations and responses on the object. Example: a sequential history of a FIFO queue q.enq(3) q:void q.enq(7) q.deq() q:3 q.deq() q:7

Sequential specification The correct behavior of the object in the absence of concurrency: a set of legal sequential object histories. Example: the sequential spec of a counter H0: H1: c.f&i() c:0 H2: c.f&i() c:0 c.f&i() c:1 H3: c.f&i() c:0 c.f&i() c:1 c.f&i() c:2 H4: c.f&i() c:0 c.f&i() c:1 c.f&i() c:2 c.f&i() c:3 . . .

Shared Objects Correctness (cont’d) Linearizability An execution is linearizable if there exists a permutation of the operations on each object o, , such that:  is a sequential history of o  preserves the partial order of the execution.

Example linearizable q.enq(x) q.enq(x) q.deq(y) q.deq(y) q.enq(y) q.deq(x) q.deq(x) time time

Example not linearizable q.enq(x) q.enq(x) q.deq(y) q.enq(y) q.enq(y) time

Wait-freedom vs. lock-freedom Wait-freedom – each process completes its operation on the in a finite number of its own steps Lock-freedom – some process completes its operation on the object after a finite number of steps is taken

The compare&swap operation Comare&swap(b,old,new) atomically v read from b if (v = old) { b new return success } else return failure; Motorola 680x0 IBM 370 Sun SPARC 80X86 MIPS PowerPC DECAlpha 12

Treiber’s stack algorithm … val val val Top next next next Push(int v, Stack S) n := new NODE ;create node for new stack item n.val := v ;write item value do forever ;repeat until success node top := S.top n.next := top ;next points to current (LIFO order) if compare&swap(S, top, n) ; try to add new item return ; return if succeeded od

Treiber’s stack algorithm (cont’d) … val val val Top next next next Pop(Stack S) do forever top := S.top if top = null return empty if compare&swap(S, top, top.next) return top.val od

Treiber’s stack algorithm (cont’d) It is easily seen that the alg is linearizable and lock-free A disadvantage of the algorithms is that… It has a sequential bottleneck.

… An elimination backoff stack algorithm (Hendler, Shavit and Yerushalmi, 2004) Key idea: pairs of push/pop operations may collide and eliminate each other without accessing a central stack. Central stack … val val val Top next next next collision array

… Collision scenarios Collision array Central stack push pop push pop val val val Top next next next

Elimination: challenges Prevent elimination chains: e.g., A collides with B, which collides with C… Prevent race conditions: e.g., A collides with B, which is already gone… Collision array push pop Top val next … Central stack

Data structures Location array collision array Each stack operation is represented by a ThreadInfo structure struct ThreadInfo { id ;the identifier of the thread performing the operation op ;a PUSH/POP opcode cell ;a cell structure spin ;duration to spin } Struct Cell { ;a representation of stack item as in Treiber pnext ;pointer to the next cell pdata ;stack item } Location array p1 p2 p3 p4 pn Thread Info Thread Info collision array p1 p7

Elimination-backoff stack code void StackOp(ThreadInfo* p) { if (TryPerformStackOP(p) == FALSE) ;if operation not applied to central stack LesOp(p) ;try to eliminate operation by colliding with an opposite-type operation return void LesOP(ThreadInfo * p) while (1) location[mypid]=p ;announce arrival pos=GetPosition(p) ;get a random position at the collision array him=collision[pos] ;read current value of that position while (!compare&swap(&collision[pos],him,mypid);try to write own ID him=collision[pos] ;continue till success if (him != empty) ;if read an ID of another thread q=location[him] ;read a pointer to the other thread’s info if (q!=NULL && q->id=him && q->op != p->op) ;if may collide if (compare&swap(&location[mypid],p,NULL) ;try to prevent unwanted collisions if (TryCollision(p,q)==true) ;if collided successfully return ;return code is already at ThreadInfo structure else goto stack ;try to apply operation to central stack else FinishCollision(p), return ;extract information and finish delay (p->spin) ;Wait for other thread to collide with me if (!compare&swap(&location[mypid],p,NULL) ;if someone collided with me FinishCollision(p), return;Extract information and finish stack: if (TryPerformStackOp(p)==TRUE) return ;try to apply operation to central stack

Elimination-backoff stack code (cont’d) void TryCollision(ThreadInfo* p, ThreadInfo *q) if (p->op==PUSH) if (compare&swap(&location[him],q,p)) ;give my record to other thread return TRUE else return FALSE if (compare&swap(&location[him],q,NULL)) p->cell=q->cell ;get pointer to PUSH operation’s cell location[mypid]=NULL; I will not have time to go over this code… void FinishCollision(ThreadInfo* p) if (p->op==POP) p->pcell=location[mypid]->pcell location[mypid]=NULL