Upload
maximillian-kennedy
View
221
Download
0
Embed Size (px)
Citation preview
November 15, 2007November 15, 2007
A Java Implementation of a A Java Implementation of a Lock-Free Concurrent Priority Lock-Free Concurrent Priority
QueueQueue
Bart VerzijlenbergBart Verzijlenberg
November 15, 2007November 15, 2007 22
AgendaAgenda
Algorithm ReviewAlgorithm Review ImplementationImplementation Java Package usedJava Package used TestingTesting ConclusionConclusion QuestionsQuestions
November 15, 2007November 15, 2007 33
Algorithm ReviewAlgorithm Review
Priority QueuePriority Queue Lock-freeLock-free Relies on atomic Compare and Swap Relies on atomic Compare and Swap
operationsoperations
November 15, 2007November 15, 2007 44
Algorithm ReviewAlgorithm Review
The algorithm uses the Skip-List data The algorithm uses the Skip-List data structurestructure Extends the Skip-List for concurrent useExtends the Skip-List for concurrent use The Skip-List is sorted on the priority of the nodesThe Skip-List is sorted on the priority of the nodes
The algorithm is lock-freeThe algorithm is lock-free No blockingNo blocking Prevent dead locksPrevent dead locks Always progress by at least one operationAlways progress by at least one operation Risk of starvationRisk of starvation
November 15, 2007November 15, 2007 55
Algorithm ReviewAlgorithm ReviewSkip-ListSkip-List
Multi-layer linked listMulti-layer linked list Probabilistic alternative to balanced Probabilistic alternative to balanced
treestrees H forward pointer for a node of height hH forward pointer for a node of height h Each pointer i points to the next node Each pointer i points to the next node
with a height of at least iwith a height of at least i Probabilistic time complexity log(N) for Probabilistic time complexity log(N) for
N nodesN nodes
November 15, 2007November 15, 2007 66
Inserting in a Skip-ListInserting in a Skip-List
Inserting 17 in the list
November 15, 2007November 15, 2007 77
ImplementationImplementation
Two classesTwo classes NodeNode
Represents an entry in the queueRepresents an entry in the queue SkipQueueSkipQueue
Contains the algorithm logicContains the algorithm logic
November 15, 2007November 15, 2007 88
Node ClassNode Class
November 15, 2007November 15, 2007 99
SkipQueue ClassSkipQueue Class
November 15, 2007November 15, 2007 1010
Java Package UsedJava Package Used
AtomicMarkableReferenceAtomicMarkableReference In Java.util.concurrent.atomicIn Java.util.concurrent.atomic
StoresStores A reference to an objectA reference to an object A boolean flagA boolean flag
Provides ability toProvides ability to Atomically set both the flag and referenceAtomically set both the flag and reference Compare and Swap (CAS) the flag and Compare and Swap (CAS) the flag and
referencereference
November 15, 2007November 15, 2007 1111
TestingTesting
Multi-threadedMulti-threaded 10 insert threads10 insert threads
Each inserting 100,000 objects with random Each inserting 100,000 objects with random integer keysinteger keys
10 delete threads10 delete threads Each deleting while the queue is not emptyEach deleting while the queue is not empty If the queue is empty, sleep for a bit and try If the queue is empty, sleep for a bit and try
again again
November 15, 2007November 15, 2007 1212
TestingTesting
Maintain a counterMaintain a counter Stores the number of nodes dequeuedStores the number of nodes dequeued
When 1,000,000 nodes removedWhen 1,000,000 nodes removed Stop the delete threadsStop the delete threads Check that Check that
the queue is emptythe queue is empty removed exactly 1,000,000 nodesremoved exactly 1,000,000 nodes
November 15, 2007November 15, 2007 1313
TestingTesting
10 insert threads10 insert threads Each inserting 100,000 random integer Each inserting 100,000 random integer
numbersnumbers When all numbers have been When all numbers have been
insertedinserted Remove them one at a time.Remove them one at a time. Making sure the nodes come out sortedMaking sure the nodes come out sorted
November 15, 2007November 15, 2007 1414
Removing AtomicityRemoving Atomicity
Do atomic references make a differenceDo atomic references make a difference i.e. does concurrency come into play, or are we i.e. does concurrency come into play, or are we
just luckyjust lucky Replace each AtomicMarkableReference Replace each AtomicMarkableReference
with a similar classwith a similar class Same functionsSame functions But they are not atomicBut they are not atomic
The queue becomes locked after a small The queue becomes locked after a small number of concurrent deletes.number of concurrent deletes.
November 15, 2007November 15, 2007 1515
ConclusionConclusion
Further testing is needed to verify Further testing is needed to verify the correctness of the the correctness of the implementationimplementation
Tests so far are positiveTests so far are positive But cannot be certain there are no But cannot be certain there are no
problemsproblems
November 15, 2007November 15, 2007
QuestionsQuestions