Lock-Free concurrent algorithm for Linked lists: Verification CSE-COSC6490A : Concurrent Object-Oriented LanguagesYork University - W09 Speaker: Alexandre Walzberg Date: May, 14th 2009 Paper: MikhailFomitchev and Eric Ruppert, Lock-Free Linked Lists and Skip Lists.PODC'04, 2004.
Plan • The algorithm - reminder • Verification of the list content • Verification of the lock-free property
1. The Algorithm - reminder Reminder C A B • Back-link allow a thread to not start research from head if it encounter a “in deletion” node. • The mark logically delete the node and avoid1) deletion of C2) Insertion of B’ between B and C • A flag prevent any operation on the node (except the deletion of the next node) Mark Flag
1. The Algorithm - reminder 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 Algorithm - reminder The class Node Node int value … 31 2 1 0 int key … 31 2 1 0 Node backlink … 31 2 1 0 AtomicStampedReference<T> next int Node … … 31 2 1 0 31 2 1 0
2. Verification of the list content Test done • Concurrent insertion/deletion of nodes1) with same key 2) with different key3) with both 4) With key in reverse order • Main problem testInsertion of all even keysInsertion of odd keys | Deletion of even keys • For each ThreadRandom delay between operation • Random operation (search / insert / delete) • Random key values
2. Verification of the list content Verification method • Insertion of random keys 0 < k < 10 000 • Array verif of 10 000 elements. • Exist and Checked are Atomic Booleans Insertion : set verif [ inserted key ].exist at trueDeletion : set verif [ inserted key ].exist at false Verification :1) Verify that all elements of the list are indeed record as existing and set checked as true.2) Verify that each element recorded has been checked.
2. Verification of the list content Verification method : limitation We can not make insertion and deletion at the same time hence actual deletion/insertion can not be atomically with recording in the array. Instead : Insertion | insertion | insertionRendez-Vous of all threadsDeletion | Deletion | Deletion For the main problem test : Insertion of all even keysInsertion of odd keys | Deletion of even keys We can just control at the end that all even keys are absent and all odd keys are present
3. Verification of thelock-free property Pre-emption Insertion of sleep( “random time”) into delete-group functions to forcepre-emption by the scheduler in the middle of a deletion (between each step) => Test of the lock-free property and distribution of the algorithm Distribution of the algorithm Comment of all lines calling the helper in other function than Deletion functions => performance decrease a lot In additions, stopping a thread in the middle of a deletion make live-locks in other threads.
3. Verification of thelock-free property Contention Live-lock indicator: Counting number of loop iteration in the algorithm using an Atomic Long (that we can Atomically increase). => Contention is negligible (less than 0.01 loop iteration / operation)
3. Verification of thelock-free property Live-Lock problem In assignment 2, I had a live-lock problem.I add a CAS operation to fix the problem. However this operation was normally not required and not part of the described algorithm. During verification, I found the problem, coming from a miss-use of the Compare And Set operation. Then I could delete this extra CAS operation.
Conclusion • JPF • No error detected for short test program with a small amount of thread • Execution too long for a big amount of thread or long test • Could not find the use of JPF. Could not find any property to check using asserts (could not find easy to check invariant) • Verification of the list content • The verification system can handle concurrent insertion and concurrent deletion but not concurrent insertion and deletion. • Verification of the lock-free property • The lock-free property is respected. The algorithm distribute task amongst threads.
Any questions ?? Thank you for your attention!