40 likes | 60 Views
Learn how the ABA problem can corrupt stacks and how to mitigate it using optimistic non-blocking techniques with practical code illustrations.
E N D
An example demonstrating the ABA problem Xinyu Feng University of Science and Technology of China
An Optimistic Non-blocking Stack Top Next Next n n … pop( ){ local done, next, t; done = false; while (!done) { t = Top; if (t==null) return null; next = t.Next; done = CAS(&Top, t, next); } return t; ABA problem leads to corrupted stacks
ABA Problem Top Top Top T2: a = pop(); b = pop(); push(a); T1: pop() { t = Top next = t.Next interrupted resumes CAS(&Top,t,next) succeeds stack corrupted t A next B C Timeline Threads T1 and T2 are interleaved as follows: