160 likes | 169 Views
This presentation discusses a lock-free priority queue algorithm using the Skip-List data structure for efficient concurrent use. It covers the issues with concurrency, atomic operations, performance, and concludes with questions.
E N D
A Concurrent Lock-Free Priority Queue for Multi-Thread Systems Bart Verzijlenberg October 16, 2007
Agenda • Introduction • Skip-List Overview • Issues with Concurrency • Lock-Free Priority Queues • Atomic Operations • Performance • Conclusion • Questions
Introduction • Priority queues are fundamental data structures • Used in a wide variety of applications • The efficient design of priority queues has been extensively researched • In order to use priority queues in a concurrent environment some type of locking is often used. • Some concurrent algorithms simply have a lock at the start of a sequential algorithm. • This locking causes blocking and may lead to starvation and deadlocks. • All are bad for system performance
Introduction contd. • Priority Queues have two general operations • DeleteMin • Insert • This algorithm uses the Skip-List data structure • Extends the Skip-List for concurrent use • The Skip-List is sorted on the priority of the nodes • To avoid the pitfalls of locking, this algorithm is lock-free
Skip-List Overview • Multi-layer linked list • Probabilistic alternative to balanced trees • Each node of height H has H pointers • Each pointer i points to the next node with a height of at least i • Probabilistic time complexity log(N) for N nodes • 50% of the nodes have height 1 • 25% of the nodes have height 2 • 12.5% of the nodes have height 3 • etc
Insert in a Skip-List Inserting 17 in the list
Issues with Concurrency • When a node is inserted or deleted we need to change multiple pointers • Both in the node, and in other nodes • Need to make these changes consistently • But not necessarily all at once
N = Get 2->NextNode (N==4) Set 1->NextNode = N Set 2->NextNode = 3 Losing a Node Deleting Node 2 Insert Node 3
Lock-Free Priority Queues • In most 32-bit systems, the address of a 32-bit value is evenly divisible by 4 • Set the 0th bit to 1 using CAS to indicate the node is being deleted • Any concurrent operation will be notified of the delete when their CAS operation fails
Insert A Node • Find where the Node should be inserted • Simply do a search of the Queue • When coming across a node being deleted, help the deletion and then continue searching • Ensure no duplicate keys • Try to insert the Node • Use a CAS operation • Starting at the bottom, set the pointers in the node. • Help delete the Node if needed • The new Node may already be getting deleted
Delete a Node • Find the node to remove • May not be the head of the queue due to deletions • Try to set the delete mark on the Node • While searching, if a Node is being deleted we help the deletion • Set the delete mark on every pointer in the node • Remove the Node, starting at the top level
Atomic Operations • Some existing algorithms require atomic operations not found on most systems. • We need only three • Test And Set (TAS) • Fetch And Add (FAA) • Compare And Swap (CAA) • All are available on most common systems
Performance • Faster than other concurrent priority queues for systems with 3 or more threads.
Conclusion • This algorithm provides a fast and lock free priority queue • Furthermore, it is also a fast lock-free concurrent linked list (Skip-List) • Currently assumes availability of pointer arithmetic. • This needs to be changed for implementation in Java