|
|
Log in / Subscribe / Register

Beingessner: Rust's Unsafe Pointer Types Need An Overhaul

Beingessner: Rust's Unsafe Pointer Types Need An Overhaul

Posted Apr 4, 2022 2:54 UTC (Mon) by ncm (guest, #165)
In reply to: Beingessner: Rust's Unsafe Pointer Types Need An Overhaul by jlombera
Parent article: Beingessner: Rust's Unsafe Pointer Types Need An Overhaul

Being absolutely clear: "volatile" is completely useless for synchronizing between threads. If you have been relying on volatile for synchronization, you are shipping bugs.

Unless you are pinging hardware registers, "volatile" is doing absolutely nothing for you, no matter how it looks to you in Godbolt. To synchronize between threads, you need memory fences, which are expressed as "atomic" types in C and C++. If you are using atomics, there is exactly zero value in adding "volatile". If you are not using atomics and not pinging hardware registers, there is exactly zero value in adding "volatile". "Volatile" appearing in code not part of an OS driver reliably indicates bugs.


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds