The module std::sync::atomic doesn't contain fixed size integral atomic types. In my 64-bit application, I need to create a vector of atomic 32-bit integers. Is there a workaround? Can I implement something like an AtomicU32 (or AtomicI32) myself, and how?
The std::intrinsics module contains intrinsic atomic functions that are generic. This means you can basically copy-paste the implementation for AtomicUsize and/or AtomicIsize and change the wrapped type from usize/isize to u32/i32.
However, these intrinsics are unstable, so you need to use a nightly Rust compiler in order to make this work. If that's not acceptable to you, consider submitting an RFC to get such types added to the standard library. If using a nightly Rust compiler is OK for you, then it might be interesting to publish a crate that contains these types. This will have the advantage of gathering statistics on how useful such types are. (Dependents will still need to use a nightly compiler though, so the effect might be somewhat underestimated.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With