Skip to content

Commit e758946

Browse files
committed
Auto merge of #28149 - jakerr:atomic, r=alexcrichton
Makes the code agree with the comment: 'value answers "am I locked?"'.
2 parents dfe9326 + 8213f01 commit e758946

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/doc/nomicon/atomics.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,18 @@ use std::sync::atomic::{AtomicBool, Ordering};
210210
use std::thread;
211211

212212
fn main() {
213-
let lock = Arc::new(AtomicBool::new(true)); // value answers "am I locked?"
213+
let lock = Arc::new(AtomicBool::new(false)); // value answers "am I locked?"
214214

215215
// ... distribute lock to threads somehow ...
216216

217-
// Try to acquire the lock by setting it to false
218-
while !lock.compare_and_swap(true, false, Ordering::Acquire) { }
217+
// Try to acquire the lock by setting it to true
218+
while lock.compare_and_swap(false, true, Ordering::Acquire) { }
219219
// broke out of the loop, so we successfully acquired the lock!
220220

221221
// ... scary data accesses ...
222222

223223
// ok we're done, release the lock
224-
lock.store(true, Ordering::Release);
224+
lock.store(false, Ordering::Release);
225225
}
226226
```
227227

0 commit comments

Comments
 (0)