Promote memory_order_consume to memory_order_acquire #381
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.
The current use case of
std::memory_order_consume
in this project was intended to provide the appropriate synchronization in cases where a consumer spins onwhile( spsc_queue.empty() ) {}
, and then attempts to use an element of the queue since the loop was broken out of, according to comments here. Consume semantics do not provide this guarantee according to the standard since there is no data dependency from the producer that can be carried to the consumer by doing a load-consume from the corresponding functions. What is needed is a load-acquire. Current compilers promotememory_order_consume
tomemory_order_acquire
. Thus, this example appears to work simply due to the promotion from consume to acquire, but would fail to generate the right synchronization instructions on weaker architectures oncememory_order_consume
is implemented as intended. Therefore, thememory_order
should be tightened tomemory_order_acquire
to guarantee visibility to the consumer.