I have a tree node structure as:
struct node
{
unsigned long key;
tbb::atomic<struct node*> lChild;
tbb::atomic<struct node*> rChild;
};
I would be doing compare_and_swap
on lChild
and rChild
.
I want make the left and right child as array elements and still be able to do CAS on individual array elements.
Note: I do not intend to do a double CAS
I tried this:
struct node
{
unsigned long key;
tbb::atomic<struct node*> childrenArray[2];
};
and this:
struct node
{
unsigned long key;
tbb::atomic<struct node**> childrenArray;
};
but here the individual array elements are not atomic. How do I modify this structure so that I can do a CAS like:
node->childrenArray[0].compare_and_swap(newNode,oldNode);