Should `AtomicPtr` be able to point to DSTs?

AtomicPtr<T> is defined as an UnsafeCell<*mut T>. A raw pointer can point to a DST (without being a fat pointer; not storing the size), and UnsafeCell already has a ?Sized bound. Unique<T> already works like that (for Boxing purposes), is there a reason for AtomicPtr to not behave in the same way? If not, I would like to submit an RFC.

Many platforms don't have atomics that can operate on double-wide values.

1 Like

Yeah, I think I phrased it poorly, I should've written unsized types. I mean having it point to them while being a thin pointer, thus not storing the size.

If you're disregarding size, then a thin *const [T] is *const T, which you can get from as_ptr, and similarly as_mut_ptr. There's no direct way to write a thin trait object, but ThinBox can encapsulate it -- then I suppose we'd need into_raw and from_raw to pass that to AtomicPtr.

1 Like

If you want to store a slice/trait object then you can just disregard the metadata and store *mut T/*mut ().

However I feel like there's room for improvement for extern types, since they are not sized but their pointers are still thin. To handle those cases AtomicPtr<T> could bound T with ?Sized + core::ptr::Thin

3 Likes

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