I am trying to use tagged pointers for handling the lock free operations on a list, in order to block the compare-and-swap (CAS) from going through if some other thread operated
The setTagMask
function returns a modified version of the pointer p
. If you store this modified pointer in your linked-list, then the list gets broken because the modified pointer does not point to a node
anymore.
The pointer is modified as follows. The pointer p
is converted to an unsigned integer which is capable to store a pointer: uintptr_t.
Then one or more bits are set according to MASK_BIT
. Finally, the result is converted back to a pointer and returned.
The function isMaskFlagSet
checks whether the mask bits are still set.
The only use case, I can image is: you have to call isMaskFlagSet
every time, before you use the pointer. If the mask bits are set, then it is prohibited to actually use the pointer.