Lock-Free concurrent algorithm for Linked lists: Implementation

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Linked Lists Chapter 4.
Data Structures ADT List
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
Circular Linked List. Agenda  What is a Circularly linked list  Why a Circular Linked List  Adding node in a new list  Adding node to list with nodes.
Data Structures: A Pseudocode Approach with C
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
1 Lock-Free Linked Lists Using Compare-and-Swap by John Valois Speaker’s Name: Talk Title: Larry Bush.
November 15, 2007 A Java Implementation of a Lock- Free Concurrent Priority Queue Bart Verzijlenberg.
Mohammad Amin Kuhail M.Sc. (York, UK) University of Palestine Faculty of Engineering and Urban planning Software Engineering Department Computer Science.
1 Lock-Free concurrent algorithm for Linked lists: Verification CSE-COSC6490A : Concurrent Object-Oriented Languages York University - W09 Speaker: Alexandre.
JAVA MEMORY MODEL AND ITS IMPLICATIONS Srikanth Seshadri
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
Model Checking Lock-Free Binary Search Tree Presented by Joanna Helga.
Advanced Locking Techniques
A Simple Optimistic skip-list Algorithm Maurice Herlihy Brown University & Sun Microsystems Laboratories Yossi Lev Brown University & Sun Microsystems.
Chapter 5 Linked Lists II
LINKED LIST’S EXAMPLES Salim Malakouti. Linked List? 523 Pointer Node ValuePointer.
November 27, 2007 Verification of a Concurrent Priority Queue Bart Verzijlenberg.
CSCS-200 Data Structure and Algorithms Lecture
CSE 501N Fall ‘09 10: Introduction to Collections and Linked Lists 29 September 2009 Nick Leidenfrost.
CS32 Discussion Section 1B Week 3 TA: Hao Yu (Cody)
Linked Lists and Generics Written by J.J. Shepherd.
Lecture 9 : Concurrent Data Structures Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit.
Recursion CSE 2320 – Algorithms and Data Structures
Healing Data Races On-The-Fly
Lock Free Linked List and Skip List
Concurrency 2 CS 2110 – Spring 2016.
Checking nonblocking concurrent queue program
Sorted Linked List Same objective as a linked list, but it should be sorted Sorting can be custom according to the type of nodes Offers speedups over non-sorted.
UNIT – I Linked Lists.
Sequences 6/3/2018 9:11 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
UNIT-3 LINKED LIST.
Week 8 - Wednesday CS221.
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
Linked Lists Damian Gordon.
Sequences 8/2/ :13 AM Linked Lists Linked Lists.
Concepts of programming languages
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
Linked Lists.
The Bag and Sequence Classes with Linked Lists
Linked List Sudeshna Sarkar.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Monday, April 16, 2018 Announcements… For Today…
Linked Lists.
Queues.
Data Structures ADT List
Data Structures ADT List
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
Sequences 12/8/2018 3:02 AM Linked Lists Linked Lists.
CS212D: Data Structures Week 5-6 Linked List.
Programming II (CS300) Chapter 07: Linked Lists and Iterators
Multicore programming
Multicore programming
A Concurrent Lock-Free Priority Queue for Multi-Thread Systems
Multicore programming
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Data Structures ADT List
Linked Lists Adapted from Dr. Mary Eberlein, UT Austin.
Multicore programming
Linked Lists.
CS148 Introduction to Programming II
Intro to OOP with Java, C. Thomas Wu By : Zanariah Idrus
Data Structures & Algorithms
Programming II (CS300) Chapter 07: Linked Lists
Queues: Implemented using Linked Lists
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Linked List Improvements
More concurrency issues
Presentation transcript:

Lock-Free concurrent algorithm for Linked lists: Implementation DAML+OIL Lock-Free concurrent algorithm for Linked lists: Implementation Speaker: Alexandre Walzberg Date: April, 28th 2009 Paper: MikhailFomitchev and Eric Ruppert, Lock-Free Linked Lists and Skip Lists.PODC'04, 2004. CSE-COSC6490A : Concurrent Object-Oriented Languages York University - W09

DAML+OIL Plan Implementation Tests Performances

1. The Implementation Reminder: a node Node value key backlink next DAML+OIL 1. The Implementation Reminder: a node Node value … 31 2 1 key … 31 2 1 backlink … 31 2 1 next … 31 2 1 2 LSB of a pointer : always 0 ! - one will represent the flag - the other one the mark Allow to update the 3 information atomically

1. The Implementation Reminder: a node Node int value long key DAML+OIL 1. The Implementation Reminder: a node Node int value … 31 2 1 long key … 31 2 1 Node backlink … 31 2 1 next … 31 2 1 2 LSB of a pointer : always 0 ! - one will represent the flag - the other one the mark Allow to update the 3 information atomically

1. The Implementation AtomicStampedReference<T> Own: DAML+OIL 1. The Implementation AtomicStampedReference<T> Own: A reference to an object of class T A Stamp (integer) Getters and Setters for the reference and the stamp Atomic CAS operation which change both the reference and the stamp atomically Reading and writing on both the reference and the stamp are Volatile public boolean compareAndSet( V expectedReference, V newReference, int expectedStamp, int newStamp)

1. The Implementation The class Node Node int value long key DAML+OIL 1. The Implementation The class Node Node int value … 31 2 1 long key … 31 2 1 Node backlink … 31 2 1 AtomicStampedReference<T> next Node int … … 31 2 1 31 2 1

1. The Implementation Flag and Mark DAML+OIL 1. The Implementation Flag and Mark Use the stamp to represent the Flag and the Mark 0: flag=0 ; mark=0 1: flag=1 ; mark=0 2: flag=0 ; mark=1 compareAndSet vs compareAndSwap var.compareAndSet(expected, new){ if(var == expected){ var = new; return true; } return false; } var.compareAndSwap(expected, new){ old = var; if(var == expected) var = new; return old; } The paper’s algorithm was using compareAndSwap. This is different of the compareAndSet function java provides. => The way to use these atomic function differ a little bit ! (but the result is the same)

1. The Implementation Class concurrentLinkedList DAML+OIL 1. The Implementation Class concurrentLinkedList private Node head, tail public Node Insert(), Delete(), Search() public void print() private SearchFrom(), SearchFrom2() private Try Flag(),TryMark(), HelpFlagged(), HelpMarked() concurrentLinkedList Node head Node Node Node tail …

1. The Implementation 5 Example: Insert(7) 10 13 DAML+OIL 1. The Implementation Example: Insert(7) public Node Insert(long k, int value){ … // search where to insert ; allocate new node while(true){ if(prevNode.getFlags() == FLAG) HelpFlagged(prevNode, prevNode.getNext()); else{ newNode.setNextAndFlag(nextNode, NONE); int result = prevNode.CASnext(nextNode, newNode, NONE, NONE); if(result == NONE && prevNode.getNext()== newNode) return newNode; if(result == FLAG) HelpFlagged(prevNode, prevNode.getNext()); while(prevNode.getFlags() == MARK) prevNode = prevNode.getBacklink(); } (prevNode, nextNode) = SearchFrom(k, prevNode); if(prevNode.getKey() == k) return null; 5 10 13

1. The Implementation 5 7 Example: Insert(7) prevNode nextNode 10 13 DAML+OIL 1. The Implementation Example: Insert(7) public Node Insert(long k, int value){ … // search where to insert ; allocate new node while(true){ if(prevNode.getFlags() == FLAG) HelpFlagged(prevNode, prevNode.getNext()); else{ newNode.setNextAndFlag(nextNode, NONE); int result = prevNode.CASnext(nextNode, newNode, NONE, NONE); if(result == NONE && prevNode.getNext()== newNode) return newNode; if(result == FLAG) HelpFlagged(prevNode, prevNode.getNext()); while(prevNode.getFlags() == MARK) prevNode = prevNode.getBacklink(); } (prevNode, nextNode) = SearchFrom(k, prevNode); if(prevNode.getKey() == k) return null; prevNode nextNode 5 10 13 newNode 7

1. The Implementation 5 7 Example: Insert(7) Will be deleted DAML+OIL 1. The Implementation Example: Insert(7) public Node Insert(long k, int value){ … // search where to insert ; allocate new node while(true){ if(prevNode.getFlags() == FLAG) HelpFlagged(prevNode, prevNode.getNext()); else{ newNode.setNextAndFlag(nextNode, NONE); int result = prevNode.CASnext(nextNode, newNode, NONE, NONE); if(result == NONE && prevNode.getNext()== newNode) return newNode; if(result == FLAG) HelpFlagged(prevNode, prevNode.getNext()); while(prevNode.getFlags() == MARK) prevNode = prevNode.getBacklink(); } (prevNode, nextNode) = SearchFrom(k, prevNode); if(prevNode.getKey() == k) return null; Will be deleted prevNode nextNode 5 10 13 newNode 7

1. The Implementation 5 7 Example: Insert(7) prevNode nextNode 13 DAML+OIL 1. The Implementation Example: Insert(7) public Node Insert(long k, int value){ … // search where to insert ; allocate new node while(true){ if(prevNode.getFlags() == FLAG) HelpFlagged(prevNode, prevNode.getNext()); else{ newNode.setNextAndFlag(nextNode, NONE); int result = prevNode.CASnext(nextNode, newNode, NONE, NONE); if(result == NONE && prevNode.getNext()== newNode) return newNode; if(result == FLAG) HelpFlagged(prevNode, prevNode.getNext()); while(prevNode.getFlags() == MARK) prevNode = prevNode.getBacklink(); } (prevNode, nextNode) = SearchFrom(k, prevNode); if(prevNode.getKey() == k) return null; prevNode nextNode 5 13 newNode 7

1. The Implementation 5 7 Example: Insert(7) prevNode nextNode 13 DAML+OIL 1. The Implementation Example: Insert(7) public Node Insert(long k, int value){ … // search where to insert ; allocate new node while(true){ if(prevNode.getFlags() == FLAG) HelpFlagged(prevNode, prevNode.getNext()); else{ newNode.setNextAndFlag(nextNode, NONE); int result = prevNode.CASnext(nextNode, newNode, NONE, NONE); if(result == NONE && prevNode.getNext()== newNode) return newNode; if(result == FLAG) HelpFlagged(prevNode, prevNode.getNext()); while(prevNode.getFlags() == MARK) prevNode = prevNode.getBacklink(); } (prevNode, nextNode) = SearchFrom(k, prevNode); if(prevNode.getKey() == k) return null; prevNode nextNode 5 13 newNode 7

1. The Implementation 5 7 Example: Insert(7) prevNode nextNode 13 DAML+OIL 1. The Implementation Example: Insert(7) public Node Insert(long k, int value){ … // search where to insert ; allocate new node while(true){ if(prevNode.getFlags() == FLAG) HelpFlagged(prevNode, prevNode.getNext()); else{ newNode.setNextAndFlag(nextNode, NONE); int result = prevNode.CASnext(nextNode, newNode, NONE, NONE); if(result == NONE && prevNode.getNext()== newNode) return newNode; if(result == FLAG) HelpFlagged(prevNode, prevNode.getNext()); else while(prevNode.getFlags() == MARK) prevNode = prevNode.getBacklink(); } (prevNode, nextNode) = SearchFrom(k, prevNode); if(prevNode.getKey() == k) return null; CASnext 1) 2) 3) prevNode nextNode 5 13 newNode 7

1. The Implementation And so on… Example: Insert(7) DAML+OIL 1. The Implementation Example: Insert(7) public Node Insert(long k, int value){ … // search where to insert ; allocate new node while(true){ if(prevNode.getFlags() == FLAG) HelpFlagged(prevNode, prevNode.getNext()); else{ newNode.setNextAndFlag(nextNode, NONE); int result = prevNode.CASnext(nextNode, newNode, NONE, NONE); if(result == NONE && prevNode.getNext()== newNode) return newNode; if(result == FLAG) HelpFlagged(prevNode, prevNode.getNext()); while(prevNode.getFlags() == MARK) prevNode = prevNode.getBacklink(); } (prevNode, nextNode) = SearchFrom(k, prevNode); if(prevNode.getKey() == k) return null; And so on…

DAML+OIL 2. Testing Classes concurrentLinkedList Node Thread listUser

Insertion of all even key Insertion of odd key | Deletion of even key DAML+OIL 2. Testing Interleaving Concurrent insertion/deletion of nodes 1) with same key 2) with different key 3) with same and different key Insertion of all even key Insertion of odd key | Deletion of even key Pre-emption effects Insertion of sleep(100) into delete-group functions to force pre-emption by the scheduler in the middle of a deletion (between each step) => Test of the lock-free property and distribution of the algorithm

2. Testing Random Insertion and deletion after random delay DAML+OIL 2. Testing Random Insertion and deletion after random delay Random operation (search / insert / delete) => TODO Random key => TODO Plan for Verification Finish testing To make the algorithm works : I add an operation compare to the described algorithm => seems to work this way but need to be CHECK See what tools can offer for lock-free algorithm verification

3. Performances Locks implementation DAML+OIL 3. Performances Locks implementation Source: http://docsun.cites.uiuc.edu/sun_docs/C/solaris_9/SUNWdev/MTP/p26.html One mutex / node Lock node during research / insertion before reading the next field Deletion: lock the previous node and then the deleted node Implemented with the finest possible granularity

DAML+OIL 3. Performances Test done on navy (8 processors)

DAML+OIL Conclusion Implementation easy to do (just translate the paper algorithm) => be carefully with some little details (compareAndSet vs CompareAndSwap) => some unexpected bugs very hard to trace and debug Seems to work well according to the test done => Are the tests cover all cases? The lock-free algorithm is much more efficient than the lock based one. => Is that possible to improve the lock-based algorithm? And… All pointer changes will be made using CAS (so we can be sure that not any process wrote between we read and we write the pointer) Flag and mark are represented by the 2 last bit of a pointer (so we can retrieve and modify these free information (pointer, flag and mark) in the same time) As the other process can help in an operation, we always have to check if it is not already inserted, marked, flagged, deleted right before the operation and each time.

Thank you for your attention! Any questions ?? Thank you for your attention!