I am going to go on a limb and say that you need a lock, and that to solve this problem there is no solution protected from blocking.
You will need to read from two addresses and write to both addresses everything is atomic. As far as I know, X86 can only atomically exchange data from one memory address and register. I do not think it is possible to exchange the contents of two memory addresses.
If you can set limits on where the pointers are, you can do it. For example, if you can guarantee that pointers are contiguous in memory, you can use 64- or 128-bit comparison / exchange in a loop.
There may be solutions for other simple cases, but I donโt think you will find a solution without blocking for the general case.
James McNellis
source share