4
$\begingroup$

Question

Given a 32-bit cmpxchg operation as a primitive:

u32 cmpxchg32(u32* mem, u32 key, u32 old, u32 neo) {
    // this function runs atomically
    u32 found = mem[key];
    if (found == old) {
        mem[key] = neo;
    }
    return found;
}

Is it possible to implement the same function, for 64-bits?

What I've tried

So far, the only progress I've had is this paper, which describes a method for implementing multi-word cmpxchg based on single-word primitives. It works for arbitrary lengths, though, and uses linked lists, insertion sort and additional heavy-weight structures to accomplish that. It, thus, looks overkill for my case, so I wonder if there is a more straightforward approach for the 32-bit -> 64-bit case.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.