#[repr(align(64))]pub struct CachePadded<T>(pub T);Expand description
In concurrent programming, false sharing is a performance-degrading situation that can arise when two or more cores are modifying different variables that reside on the same cache line.
Cache lines are assumed to be N bytes long, where N depends on the architecture:
x86_64, aarch64 and powerpc: 64 bytes, but N is 128 as prefetching pulls pairs of cache lines on some CPUs.- arm, mips, mips32r6, mips64, mips64r6, sparc and hexagon: 32 bytes
- m68k: 16 bytes
- s390x: 256 bytes
- others: 64 bytes. Just some default for other architectures.
Note that alignment MAY be different than cache line size of the actual CPU the program runs on, as cache line size vary between CPUs with the same architecture.
This structure contains a single value of type T that is aligned to cache lines, removing false sharing.
It derives common traits for convenience.
Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: Clone> Clone for CachePadded<T>
impl<T: Clone> Clone for CachePadded<T>
Source§fn clone(&self) -> CachePadded<T>
fn clone(&self) -> CachePadded<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for CachePadded<T>
impl<T: Debug> Debug for CachePadded<T>
Source§impl<T: Default> Default for CachePadded<T>
impl<T: Default> Default for CachePadded<T>
Source§fn default() -> CachePadded<T>
fn default() -> CachePadded<T>
Returns the “default value” for a type. Read more
Source§impl<T> Deref for CachePadded<T>
impl<T> Deref for CachePadded<T>
Source§impl<T> DerefMut for CachePadded<T>
impl<T> DerefMut for CachePadded<T>
Source§impl<T: Hash> Hash for CachePadded<T>
impl<T: Hash> Hash for CachePadded<T>
Source§impl<T: Ord> Ord for CachePadded<T>
impl<T: Ord> Ord for CachePadded<T>
Source§fn cmp(&self, other: &CachePadded<T>) -> Ordering
fn cmp(&self, other: &CachePadded<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq> PartialEq for CachePadded<T>
impl<T: PartialEq> PartialEq for CachePadded<T>
Source§impl<T: PartialOrd> PartialOrd for CachePadded<T>
impl<T: PartialOrd> PartialOrd for CachePadded<T>
impl<T: Copy> Copy for CachePadded<T>
impl<T: Eq> Eq for CachePadded<T>
impl<T> StructuralPartialEq for CachePadded<T>
Auto Trait Implementations§
impl<T> Freeze for CachePadded<T>where
T: Freeze,
impl<T> RefUnwindSafe for CachePadded<T>where
T: RefUnwindSafe,
impl<T> Send for CachePadded<T>where
T: Send,
impl<T> Sync for CachePadded<T>where
T: Sync,
impl<T> Unpin for CachePadded<T>where
T: Unpin,
impl<T> UnwindSafe for CachePadded<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more