crossbeam
crossbeam copied to clipboard
AtomicCell for struct's those size is not the power of two
Is it possible to use AtomicCell for struct where underlying atomic type is rounded up to the nearest power of two? For example this would use AtomicU32
struct Foo {
foo: u16,
bar: u8,
}
This would use AtomicU64
struct Foo {
foo: u16,
bar: u8,
bar1: u8,
bar2: u8,
}
I don't know the internal workings of AtomicCell
, but I think if this is possible, the usage cases will increase
You can use AtomicCell
, but it won't be lock-free.
One of the conditions for AtomicCell<T>
to use the atomic type is that T
has at least the same alignment as the size.
So you can use the repr
attribute to adjust the alignment.
#[repr(align(4))]
struct Foo {
foo: u16,
bar: u8,
_padding: u8,
}