I am trying to work on a lockfree solution for a self organizing list. I recently found out about the tagged pointers and thought it could work for me.
I have my node structure as follows:
typedef struct node {
unsigned long val;
struct node * next;
} node_t;
And I want to use on this the compare_exchange_strong function from the atomic library
std::atomic<node_t*> nodeAtomic;
nodeAtomic.store(node, std::memory_order_seq_cst);
nodeAtomic.compare_exchange_strong(nodeNew, node, std::memory_order_seq_cst)
and for example if a thread is working on a node the cas should not go through because this lower bit will not match.
My questions are:
- How can I set this bit without losing the references that the node has (next & val)?
- How can I set it back?