Tagged Pointers for lockFree list in C

前端 未结 1 1221
灰色年华
灰色年华 2021-01-23 16:56

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

相关标签:
1条回答
  • 2021-01-23 17:36

    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.

    0 讨论(0)
提交回复
热议问题