0

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:

  1. How can I set this bit without losing the references that the node has (next & val)?
  2. How can I set it back?
moriczCJ
  • 23
  • 3
  • http://stackoverflow.com/questions/1845482/what-is-uintptr-t-data-type – n. m. could be an AI Feb 28 '16 at 17:00
  • 1
    Even if you could do this, it won't offer any benefit for you. Tagged pointers operate on a per-pointer-variable basis. If one thread uses one pointer variable to access a node, and uses that variable's bits to implement locking, another thread could use a completely different pointer variable to access the same node and bypass the lock. The lock would only work if both threads share the same pointer variable. – Remy Lebeau Feb 28 '16 at 17:01
  • I think he is indeed referring to a shared pointer variable and he just wants to be able to set the unused bits in a pointer for the CAS operation. – Tamas Ionut Mar 01 '16 at 07:09

0 Answers0