There’s No Such Thing as “Implicitly Atomic”

In this web content, the author addresses a question about the behavior of aligned machine-word-sized variables in multi-threaded programs. They clarify that although it is unlikely for these variables to have “torn” values (mix of old and new values) due to modern processors guaranteeing atomicity, there are other factors to consider. For example, if the variable is an instance, global, or static variable, Swift’s dynamic exclusivity checks may come into play. Additionally, even with a direct access through UnsafePointer, the desired behavior is not guaranteed, as tools like Thread Sanitizer can still detect issues. The author also mentions the possibility of future technologies enforcing stricter memory access rules for improved performance and correctness. They conclude by advising against using a single non-atomic load or store to communicate across threads without synchronization in Swift, C, or Rust.

https://belkadan.com/blog/2023/10/Implicity-Atomic/

To top