Skip to main content

has_false_sharing

Function has_false_sharing 

Source
pub fn has_false_sharing(layout: &StructLayout) -> bool
Expand description

Return true if any cache line contains two or more Concurrent fields with different lock guards — a confirmed false-sharing hazard.

§Heuristic tightening

The type-name heuristic assigns each field’s own name as its guard, so two AtomicU64 fields always receive different guards and would naively trigger this check. However, two purely-atomic fields sharing a cache line is a performance concern (cache-line bouncing) rather than false sharing in the classical lock-based sense. To avoid noisy findings from the heuristic, we only flag a conflict when at least one of the two fields has is_atomic: false (i.e. it is a mutex/lock type, or was explicitly annotated as lock-protected data).

Explicit guard annotations (GUARDED_BY, #[lock_protected_by], etc.) always set is_atomic: false, so annotated conflicts are always reported.