Checking nonblocking concurrent queue program Jun Miao York University 5/9/2018
Concurrent Queue Queue is a widely used ADT in computer science Insertions and deletions follow the first-in first-out scheme
Node Structure Node <V> V item; AtomicStampedReference<Node<V>> next; AtomicStampedReference ReferenceIntegerPair<V>: private final V reference private final int integer
Dummy Node <null, null> Initialization Node<E> dummy = new Node<E>(null,null); this.head = new AtomicStampedReference<Node<E>>(dummy,0); this.tail = new AtomicStampedReference<Node<E>>(dummy,0); head tail Stamp = 0 Reference Dummy Node <null, null> Stamp = 0 Reference
Enqueue If NO CompareAndSet is used in 3 steps Create a new node Store current Tail and last node Is current Tail unchanged? Is the stored node still the last one? Insert the node at the end Update reference of Tail to new node If NO CompareAndSet is used in 3 steps Swing Tail to the last node
Dequeue Is current Head unchanged? Store current Head, Tail, and the first available node Is the queue empty? Get information from the first available node Update Head Is current Head unchanged? Are Head and Tail pointing to the same node because Tail is not updated?
Properties no uncaught exceptions no data races All listeners can be found in javapathfinder-trunk\src\gov\nasa\jpf\tools
NullPointerException Problem: q.head points to a null node The only possible reason: 1. q.head != q.tail 2. q.head.next == null But how does this happen?
Struggling with NullPointerException NonNullChecker is used First Attempt 2 threads Thread 1 Enqueue() Dequeue() Thread 2
Simple is good Second Attempt Start from 1 thread with 1 operation 2 threads: 2 enqueue , 2 dequeue, 1 enqueue and 1 dequeue 3 threads: 3 enqueue …. 4 threads: 4 enqueue… Result:
PreciseRaceDetector Two threads Three threads… Four thread… Result: Enqueue|Dequeue Enqueue|Enqueue Dequeue|Dequeue Three threads… Four thread… Result:
Exceptions and Data races No Exceptions in the concurrent queue operations No Data races My question: is my testing enough?
Something interesting This algorithm came out of a discussion with Franck van Breugel and Sergey Kulikov from the University of York. All credits for it goes to Franck and Sergey, all the bugs are mine. Author: Willem Visser
Post Condition Start from q.head Print value of each node sequentially Reach q.tail
Conclusion Testing the program step by step The more enqueue operation, the more time consumed by JPF checking Testing time increases significantly
Question Time