How do I steal 2 MSBs from an address to do an atomic operation? I'm trying to do a single word CAS
An example
public class Node
{
long key;
long value;
Node lchild; // format is flag1,flag2,address
Node rchild; // format is flag1,flag2,address
}
public void createNode()
{
Node n1 = new Node(); //this should create a node with format 0,0,address1
}
public void setFlag1(Node n1)
{
Now the new address should be in format 1,0,address1
}
public void setFlag2(Node n1)
{
Now the new address should be in format 0,1,address1
}
AtomicReference
could be used if I needed only one extra flag.
AtomicStampedReference
could be used but it is not efficient as it creates an extra box containing timeStamp and a reference.
A similar problem in C is discussed in stealing bits from a pointer
java.util.concurrent.AtomicReference
work for you? – BorneNode n1 = new Node()
, would the operating system always assign a space which is word aligned? I'm trying to steal MSBs to avoid ABA problem which can happen withcompareAndSwap
. Also can you please explain why stealing from LSBs is more efficient? – Designationnative
code. – SonneteerAtomicStampedReference
and found that it performed too poorly? – SurfacetosurfaceAtomicStampedReference
is used, each step in traversing down the tree requires to dereference theAtomicStampedReference
object to get the reference to the child. – Designationjava RTTI
solve my problem completely? I haven't implemented it yet. Before that, will using RTTI be faster thanatomicStampedRefence
? – Designation