`AtomicDoubleUsize`?

Hello, some architectures have instructions to atomically load 2 words, like cmpxchg16b on x86_64. I don't think AtomicU128 is an answer, because there might be 32-bit architectures that allow 64 bit loads. That's why we have AtomicUnsize. Can we then have something like AtomicDoubleUsize or something similar?

You could define it yourself:

#[cfg(target_pointer_width = "16")]
pub type AtomicDoubleUsize = std::sync::atomic::AtomicU32;

#[cfg(target_pointer_width = "32")]
pub type AtomicDoubleUsize = std::sync::atomic::AtomicU64;

#[cfg(target_pointer_width = "64")]
pub type AtomicDoubleUsize = std::sync::atomic::AtomicU128;

But this assumes that native register size is == pointer size == there is support for atomic operations with wish double of that

Under strict provenance, there are issues with using (atomic) integer types to hold pointers—which makes even having an AtomicDoubleUsize type or similar of limited use in such cases.

I raised this very concern in the unsafe code guidelines issue tracker a couple of days ago, and there has been some interesting discussion there since.

4 Likes

That sounds like we should have both AtomicDoubleUsize and AtomicDoublePtr, with the same relationship as AtomicUsize and AtomicPtr.

2 Likes

There's also #[cfg(target_has_atomic="128")] which could be used to provide a fallback like Mutex.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.