Add compare_exchange, compare_exchange_weak, and fetch_update #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements atomic CAS operations (
compare_exchange
,compare_exchange_weak
, andfetch_update
) on potentially uninitialized integers.(If this approach is okay) This should be effectively the last requirement to use this crate (as optional deps/experimental features) in crossbeam (and to fix AtomicCell's remaining UBs such as crossbeam-rs/crossbeam#315, crossbeam-rs/crossbeam#748).
Note that this implementation already allows failure ordering stronger than success ordering (rust-lang/rust#98383).
I have not yet documented the pitfall of CAS with values containing uninitialized bytes(EDIT: documented): Comparison of two values containing uninitialized bytes may fail even if they are equivalent as Rust's type, because their contents are not frozen until a pointer to the value containing uninitialized bytes is passed toasm!
. (See crossbeam-rs/crossbeam#315 for more)For example, the following example could be an infinite loop:
To work around this problem, you need to use a helper like this function in crossbeam.