Lock Free Linked List and Skip List Eric

  • Slides: 10
Download presentation
Lock Free Linked List and Skip List Eric Ruppert Mikhail Fomitchev

Lock Free Linked List and Skip List Eric Ruppert Mikhail Fomitchev

Concurrent Algorithm Why this Algorithm is significant : • Building blocks for many other

Concurrent Algorithm Why this Algorithm is significant : • Building blocks for many other Data structures. • Better performance than earlier algorithms Problems with Mutual Exclusion: 1. 2. delay of one process can cause performance degradation and priority inversion When halting failures occur entire system fails.

General Problem in lock free system When a process is deleting node X by

General Problem in lock free system When a process is deleting node X by performing a C&S on X’s predecessor, and a concurrent operation changes X’s Right pointer results in incorrect executions Harris’s Solution Introduced Mark bits and 2 -step Deletion process but still problem persists.

Problem with Deletion • • Process P 1 wants to insert a node after

Problem with Deletion • • Process P 1 wants to insert a node after node X Process P 2 attempts to delete node X. When P 1 and P 2 performs concurrent operations and suppose that, just before P 1 is about to execute C&S, P 2 marks node X, then P 1 will fail. Then P 1 has to restart from the beginning of the list which leads to poor performance.

Harri’s Two Step Deletion A B C A Initial configuration B C A 1.

Harri’s Two Step Deletion A B C A Initial configuration B C A 1. Marking B 2. Physical Deletion Three Step Deletion in This Algorithm A B C A A B C Step 2: Setting the backlink and marking B C Step 1. Marking Initial configuration A C B C Step 3: Physical Deletion

Key Techniques • Back link pointers which points to previous node • Mark bit

Key Techniques • Back link pointers which points to previous node • Mark bit which is used as a toggle to indicate whether a node’s right pointer can be changed. • Flag bit to indicate deletion of node is on the way and its successor is fixed. Thus when P 1 finds a node marked, it traverses to its predecessor by using back link pointer and traverses until it finds an unmarked node U. Then it adds the node after U. This gives a better performance than restarting from beginning of list.

Algorithm Pre-requisites : • • The linked list is ordered by their keys Duplicates

Algorithm Pre-requisites : • • The linked list is ordered by their keys Duplicates are not allowed in the list Each node has : Key , Element , Backlink and Successor has : Right pointer, Mark bit and Flag bit Insertion : 1. Calls the sub-routine Search. From to identify where to insert the new key. Search. From returns two nodes n 1 and n 2 such that n 1. right = n 2 and n 1. key ≤ k < n 2. key. 2. Check for duplicates and create and insert new node

Scenarios: 1. prev_node may be flagged calls Help. Flagged routine, which helps to complete

Scenarios: 1. prev_node may be flagged calls Help. Flagged routine, which helps to complete the deletion and removes the flag. 2. prev_ node got marked. Insert traverses the backlinks until it finds an unmarked node and then sets prev node to point to it (lines 17 -18). In any case, in line 19 Insert invokes Search. From starting from prev node to find the correct location for the insertion in the updated list, and updates its prev node and next node pointers. Then Insert enters the next iteration of the loop. Deletion : 1. Calls Search. From, and then calls Try. Flag to perform the first deletion step (flagging the predecessor). Try. Flag – repeatedly attempts to flag del node’s predecessor, until the flag is placed or del node gets deleted. Try. Flag returns two values: a node pointer prev node and a boolean result value.

Scenarios : • 1. If already flagged, returns pre_node and result = false •

Scenarios : • 1. If already flagged, returns pre_node and result = false • 2. If del_node already deleted, returns null and false. If prev node returned is not null, it performs second and third steps of deletion by calling try mark and help marked. Amortised cost : T(s) € O(n(s) + c(s)) S – operation , n – no of elements in list and c(s) – concurrent overhead during the opeartion S.

Thank You

Thank You