CSE 305 - Tutorial 8a - Lock-free data structures
In this tutorial, you will be asked to implement classes/functions described below. The exact definitions and automated tests are given to you in the following archive.
In the lock-free
SetListmarks were used for deleting nodes (see the third section of the lecture). In this exercise, you are asked to implement a classMonotonicLockFreeSetwhich implements a lock-free set based on a list with onlyaddandcontainsmethods.Hint: instead of
AtomicMarkedReferencefrom the lecture, you can use just atomic pointer. Note that, unlike an atomic pointer, atomic shared pointer will likely be not lock-free.In the provided td8.cpp, you are given a class
BSTimplementing binary search trees with only three operations:search,insert, andsize(noremove). In this binary search tree all keys are distinct, andinsertreturns false if the key is already present. Complete the implementation ofLockFreeBSTmaking theBSTclass thread-safe using the lock-free approach.Implement the
AtomicMarkableReferenceclass from the lecture using a combination ofstd::atomicinstantiated at the user-defined structureRefAndMark(provided in td08.cpp). You are not allowed to use locks.Remark The size of the structure
RefAndMarkon your computer will very likely exceed 64 bites, so thestd::atomicof it will very likely be not lock-free itself (you can check this withis_lock_freemethod). This might be a bit annoying because any lock-free data structure based on such a class will not be honestly lock-free, but we will ignore this for now. For a method to make it likely lock-free, see the discussion here.Remark If you are checking your implementation with valrgind (and I encourage you to do so), you might get puzzling Conditional jump or move depends on uninitialised value. It is likely not to be an error, this is to be expected when using
compare_exchange_weakwith custom structures (see discussion).
Upload your file td8.cpp: