1 / 16

A Java Implementation of a Lock-Free Concurrent Priority Queue

A Java Implementation of a Lock-Free Concurrent Priority Queue. Bart Verzijlenberg. Agenda. Algorithm Review Implementation Java Package used Testing Conclusion Questions. Algorithm Review. Priority Queue Lock-free Relies on atomic Compare and Swap operations. Algorithm Review.

kiril
Download Presentation

A Java Implementation of a Lock-Free Concurrent Priority Queue

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Java Implementation of a Lock-Free Concurrent Priority Queue Bart Verzijlenberg

  2. Agenda • Algorithm Review • Implementation • Java Package used • Testing • Conclusion • Questions

  3. Algorithm Review • Priority Queue • Lock-free • Relies on atomic Compare and Swap operations

  4. Algorithm Review • The 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 • The algorithm is lock-free • No blocking • Prevent dead locks • Always progress by at least one operation • Risk of starvation

  5. Algorithm ReviewSkip-List • Multi-layer linked list • Probabilistic alternative to balanced trees • H forward pointer for a node of height h • Each pointer i points to the next node with a height of at least i • Probabilistic time complexity log(N) for N nodes

  6. Inserting in a Skip-List Inserting 17 in the list

  7. Implementation • Two classes • Node • Represents an entry in the queue • SkipQueue • Contains the algorithm logic

  8. Node Class

  9. SkipQueue Class

  10. Java Package Used • AtomicMarkableReference • In Java.util.concurrent.atomic • Stores • A reference to an object • A boolean flag • Provides ability to • Atomically set both the flag and reference • Compare and Swap (CAS) the flag and reference

  11. Testing • Multi-threaded • 10 insert threads • Each inserting 100,000 objects with random integer keys • 10 delete threads • Each deleting while the queue is not empty • If the queue is empty, sleep for a bit and try again

  12. Testing • Maintain a counter • Stores the number of nodes dequeued • When 1,000,000 nodes removed • Stop the delete threads • Check that • the queue is empty • removed exactly 1,000,000 nodes

  13. Testing • 10 insert threads • Each inserting 100,000 random integer numbers • When all numbers have been inserted • Remove them one at a time. • Making sure the nodes come out sorted

  14. Removing Atomicity • Do atomic references make a difference • i.e. does concurrency come into play, or are we just lucky • Replace each AtomicMarkableReference with a similar class • Same functions • But they are not atomic • The queue becomes locked after a small number of concurrent deletes.

  15. Conclusion • Further testing is needed to verify the correctness of the implementation • Tests so far are positive • But cannot be certain there are no problems

  16. Questions

More Related