CSE 305 - Tutorial 7 - Lazy and 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.
Improve the lazy version of
SetList(provided in the archive, see the second section of the lecture) toMultisetList, a class implementing a multiset, that is, a set that contains each element with a multiplicity. Theaddmethod will increase the multiplicity by one if the element is already in the set. Theremovemethod will descrease the multiplicity if it is positive, and returnfalseonly if there was no such element in the set.Note that, if you store the multiplicity, you do not need the
markedfield anymore.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.
Upload your file td7.cpp:
The following problem is optional.
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 td7.cpp: