Fixing Undefined Behavior in Rust's Sequence Locks with ByteAtomic

Safe Lock-free Primitives with iceoryx2's ByteAtomic

Fixing Undefined Behavior in Rust's Sequence Locks with ByteAtomic

Sequence locks are a common lock-free technique, but in Rust and C++ they still cause data races and undefined behavior when copying non-atomic data. iceoryx2's new ByteAtomic wrapper solves this by performing byte-wise atomic reads and writes, ensuring memory copies are safe. The challenge was handling padding bytes and uninitialized memory, which led to the AtomicCopy trait and a derive macro. This enables correct and safe sequence locks today, without waiting for an 'atomic memcpy' in the standard library.

Even if the reader detects that the data was modified and discards the copy before use, the act of copying the non-atomic data itself still triggers undefined behavior.

More from this day

2026-08-04