diff options
| author | bors <bors@rust-lang.org> | 2016-06-09 21:29:26 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-09 21:29:26 -0700 |
| commit | c09d546ee512c166c2e28306ed67dcf0e3fec751 (patch) | |
| tree | a91b9ea3ca88414c8123cd1cbb6cef9121d44c8a /src/liballoc_system | |
| parent | 2798772b51e58ff825a226bbf30bf8bb9fe69a33 (diff) | |
| parent | 8841f26e94705490b19f15479e86b3986549f8bb (diff) | |
| download | rust-c09d546ee512c166c2e28306ed67dcf0e3fec751.tar.gz rust-c09d546ee512c166c2e28306ed67dcf0e3fec751.zip | |
Auto merge of #34046 - Vtec234:fix-atomic-doc, r=steveklabnik
Fix wrong statement in compare_exchange doc
The documentation for `core::sync::atomic::AtomicSomething::compare_exchange` contains a wrong, or imprecise, statement about the return value. It goes:
The return value is a result indicating whether the new value was written and containing
the previous value. On success this value is guaranteed to be equal to `new`.
In the second sentence, `this value` is gramatically understood as referring to `return value` from the first sentence. Due to how CAS works, the returned value is always what was in the atomic variable _before_ the operation occurred, not what was written into it during the operation. Hence, the fixed doc should say:
The return value is a result indicating whether the new value was written and containing
the previous value. On success this value is guaranteed to be equal to `current`.
This version is confirmed by the runnable examples in variants of `AtomicSomething`, e.g.
assert_eq!(some_bool.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed),
Ok(true));
where the returned value is `Ok(current)`. This PR fixes all occurrences of this bug I could find.
An alternative solution would be to modify the second sentence so that it refers to the value _written_ into the Atomic rather than what was there before, in which case it would be correct. Example alternative formulation:
On success the value written into the `bool`/`usize`/`whatever` is guaranteed to be equal to `new`.
r? @steveklabnik
Diffstat (limited to 'src/liballoc_system')
0 files changed, 0 insertions, 0 deletions
