Does a (standard) atomic wide pointer implementation exist?

The ABA Problem can cause issues and is often resolved using wide atomic pointers. As Rust supports wide pointers for raw slices and trait objects, I thus ask:
Does a (standard) atomic wide (either pointer+usize or pointer+pointer) pointer implementation exist in the Rust community or stdlib?

x86 doesn't have 128-bit atomics. There is a workaround by using AtomicPtr<Box<dyn Trait>>.

1 Like

This is not completly true. There are extensions that support them, for example CMPXCHG16B, which is for example required for running Windows 10.

Edit: there's core::arch::x86_64::cmpxchg16b and the portable-atomic crate for a wrapper over it.

This is gonna be a pointer to a wide pointer to the actual data, which won't solve the problem.


Probably not since the standard atomics are based on C++20 which doesn't support double wide compare and swap. x86-64 doesn't have atomic 128 bit loads and stores, not efficient ones anyway. So it doesn't fit into their standard notion of what methods atomics should support. This is unfortunate since some very basic lock-free data structures require this or a load-locked / store-conditional. Also you can't do things like AARC (actually atomic reference counting) which doesn't require ownership to copy or dereference. There's no technical reason you couldn't provide a special api for those cases but there you have it.

I once did a pre-C++11 AARC implementation once on x86-64 and powerpc with inline assembler where needed. I looked into porting to standard C++ atomics and gave up since double wide compare and swap wasn't supported. Not really a loss since reference counting is really non-performant. There are much better ways than using reference counting for shared storage management.

Joe Seigh

And Windows 8 as well I believe. So if we ever drop support for Windows 7, all supported Windows targets would ostensibly have it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.