Skip to content

Commit 9638c35

Browse files
committed
Rename compare_exchange_strong to compare_exchange
1 parent 33da8e8 commit 9638c35

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

text/0000-extended-compare-and-swap.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ While all of these variants are identical on x86, they can allow more efficient
2424
# Detailed design
2525
[design]: #detailed-design
2626

27-
Since `compare_and_swap` is stable, we can't simply add a second memory ordering parameter to it. This RFC proposes deprecating the `compare_and_swap` function and replacing it with `compare_exchange_strong` and `compare_exchange_weak`, which match the names of the equivalent C++11 functions.
27+
Since `compare_and_swap` is stable, we can't simply add a second memory ordering parameter to it. This RFC proposes deprecating the `compare_and_swap` function and replacing it with `compare_exchange` and `compare_exchange_weak`, which match the names of the equivalent C++11 functions (with the `_strong` suffix removed).
2828

29-
## `compare_exchange_strong`
29+
## `compare_exchange`
3030

3131
A new method is instead added to atomic types:
3232

3333
```rust
34-
fn compare_exchange_strong(&self, current: T, new: T, success: Ordering, failure: Ordering) -> T;
34+
fn compare_exchange(&self, current: T, new: T, success: Ordering, failure: Ordering) -> T;
3535
```
3636

3737
The restrictions on the failure ordering are the same as C++11: only `SeqCst`, `Acquire` and `Relaxed` are allowed and it must be equal or weaker than the success ordering. Passing an invalid memory ordering will result in a panic, although this can often be optimized away since the ordering is usually statically known.
3838

39-
The documentation for the original `compare_and_swap` is updated to say that it is equivalent to `compare_exchange_strong` with the following mapping for memory orders:
39+
The documentation for the original `compare_and_swap` is updated to say that it is equivalent to `compare_exchange` with the following mapping for memory orders:
4040

4141
Original | Success | Failure
4242
-------- | ------- | -------
@@ -54,7 +54,7 @@ A new method is instead added to atomic types:
5454
fn compare_exchange_weak(&self, current: T, new: T, success: Ordering, failure: Ordering) -> (T, bool);
5555
```
5656

57-
`compare_exchange_strong` does not need to return a success flag because it can be inferred by checking if the returned value is equal to the expected one. This is not possible for `compare_exchange_weak` because it is allowed to fail spuriously, which means that it could fail to perform the swap even though the returned value is equal to the expected one.
57+
`compare_exchange` does not need to return a success flag because it can be inferred by checking if the returned value is equal to the expected one. This is not possible for `compare_exchange_weak` because it is allowed to fail spuriously, which means that it could fail to perform the swap even though the returned value is equal to the expected one.
5858

5959
A lock free algorithm using a loop would use the returned bool to determine whether to break out of the loop, and if not, use the returned value for the next iteration of the loop.
6060

0 commit comments

Comments
 (0)