I am currently working on a class assignment where I need to implement a lock-free linked list. The structure of each of my nodes is essentially:
class Node {
std::shared_ptr<Node> next;
long long key;
}
I need to somehow embed an extra bit of data into the "next" pointer. I cannot use an extra boolean field, because the "next" pointer needs to be updated atomically using compare_exchange_strong(). I also have to use a std::shared_ptr for its garbage collection abilities; performing memory reclamation on a lock-free data structure is beyond the scope of what we have studied in the course so far.
If I were using a plain old pointer, I could use bit manipulation operators to "twiddle" the high bit of the pointer, but clearly this won't work, because once I twiddle the bit, the pointer points to an invalid memory location, and when the assignment operator attempts to access the control block, it will cause a segmentation violation.
Can anyone offer any insights on how I can accomplish this?
Oh, and for those who are curious, I am using g++-4.8.2 on a Linux system.