A CAS that operates atomically on two pointers at once is useful for writing lock-free algorithms.
This would be an intrinsic for CMPXCHG8B, CMPXCHG16B, CASPAL instructions
Something like:
struct AtomicPair<TFirst, TSecond> where TFirst:class, TSecond:class
{
public TFirst First;
public TSecond Second;
}
struct AtomicPair<T> where T:class
{
public T First;
public nint Second;
}
struct AtomicPair
{
public nint First;
public nint Second;
}
class Interlocked
{
// upon return, comparand is updated to the value that was in location1.
public static bool CompareExchange(ref AtomicPair location1, AtomicPair value, ref AtomicPair comparand);
public static bool CompareExchange<T>(ref AtomicPair<T> location1, AtomicPair<T> value, ref AtomicPair<T> comparand);
public static bool CompareExchange<TFirst, TSecond>(ref AtomicPair<TFirst, TSecond> location1, AtomicPair<TFirst, TSecond> value, ref AtomicPair<TFirst, TSecond> comparand);
}
A CAS that operates atomically on two pointers at once is useful for writing lock-free algorithms.
This would be an intrinsic for
CMPXCHG8B,CMPXCHG16B,CASPALinstructionsSomething like: