Read_once(), Write_once(), but Not for Rust
4 months ago
- #Rust
- #Concurrency
- #Linux Kernel
- READ_ONCE() and WRITE_ONCE() macros are essential for lockless algorithms and device-memory access in the Linux kernel.
- Rust developers prefer using the Atomic crate over READ_ONCE() and WRITE_ONCE() for clearer semantics in concurrent programming.
- The Rust approach emphasizes specifying precise guarantees for operations, contrasting with the more ambiguous semantics of READ_ONCE() and WRITE_ONCE().
- Differences in concurrent data access APIs between Rust and C may complicate kernel development, requiring understanding of both approaches.
- The discussion around Rust's alternatives has highlighted potential improvements needed in C code, such as proper use of WRITE_ONCE().
- Volatile accesses in Rust are considered unsound for inter-thread communication, leading to debates on proper synchronization methods.
- Relaxed atomics in Rust are suggested as a more efficient and semantically clear alternative to volatile operations for certain use cases.