1
Lock-Free concurrent algorithm for Linked lists: Verification
CSE-COSC6490A : Concurrent Object-Oriented Languages York University - W09
Speaker: Alexandre Walzberg
Date: May, 14th 2009
Paper: MikhailFomitchev and Eric Ruppert, Lock-Free Linked Lists and Skip Lists.PODC'04, 2004.
2
PlanPlan
1. The algorithm - reminder
2. Verification of the list content
3. Verification of the lock-free property
3
1. The Algorithm - reminder1. The Algorithm - reminder
A C
• 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)
B
Reminder
Mark
Flag
4
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 - reminder1. The Algorithm - reminder
5
The class Node
AtomicStampedReference<T> next
31 012
Node backlink31 012
int key31 012
int value31 012
Node
…
…
…
…
31 012…Node int
1. The Algorithm - reminder1. The Algorithm - reminder
6
2. Verification of the list content
Test done
Concurrent insertion/deletion of nodes1) with same key 2) with different key
3) with both 4) With key in reverse order
Main problem testInsertion of all even keys
Insertion of odd keys | Deletion of even keys
For each ThreadRandom delay between operation
Random operation (search / insert / delete)Random key values
7
Verification method
2. Verification of the list content
• Insertion of random keys 0 < k < 10 000
• Array verif of 10 000 elements.
• Exist and Checked are Atomic Booleans
Index 0 1 … 9 999
Exist True False False
Checked
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.
8
Verification method : limitation
2. Verification of the list content
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 keys
Insertion 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
9
Pre-emption
3. Verification of thelock-free property
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.
10
Contention
3. Verification of thelock-free property
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)
11
Live-Lock problem
3. Verification of thelock-free property
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.
12
ConclusionConclusion
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.
13
Any questions ??
Thank you for your attention!