[Day15] Read Rust Atomics and Locks — Intro of Atmoics

By Mara Bos

R4 Cheng
Jun 6, 2023

At Topics: Chapter 2. Atomics

From: Chapter 2. Atomics

To: Chapter 2. Atomics

Notes

  • Atomic operations allow for different threads to safely read and modify the same variable
  • Eg. std::sync::atomic::AtomicI32;, std::sync::atomic::AtomicUsize
  • Almost all platforms provide at least all atomic types up to the size of a pointer
  • By interior mutability, they allow modification through a shared reference
  • They all have the same interface with methods for storing and loading and atomic “fetch-and-modify”
  • Every atomic operation takes an argument of type std::sync::atomic::Ordering: To guarantee we get about the relative ordering of operations

--

--

R4 Cheng
R4 Cheng

Written by R4 Cheng

「0」が過去で「1」が未来「今」は何処にもない

No responses yet