Promote memory_order_consume to memory_order_acquire
authorAlejandro <lucenadeveloper@gmail.com>
Thu, 19 May 2016 16:19:54 +0000 (09:19 -0700)
committerFacebook Github Bot 4 <facebook-github-bot-4-bot@fb.com>
Thu, 19 May 2016 16:23:27 +0000 (09:23 -0700)
commit05cdf111f5e6a4585a5e9140fda26f4fea070637
tree66db75fece4a0c63552495157a793c132afde961
parenta56a988a8cd07c7e3250f27594b8f92c9274b30d
Promote memory_order_consume to memory_order_acquire

Summary:
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 on `while( spsc_queue.empty() ) {} `, and then attempts to use an element of the queue since the loop was broken out of, according to comments [here](https://reviews.facebook.net/D48141). 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 promote `memory_order_consume` to `memory_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 once `memory_order_consume` is implemented as intended.  Therefore, the `memory_order` should be tightened to `memory_order_acquire` to guarantee visibility to the consumer
Closes https://github.com/facebook/folly/pull/381

Reviewed By: djwatson

Differential Revision: D3173574

Pulled By: nbronson

fbshipit-source-id: b109be2e74f016750a3fe1f848e3fc66e609b9d2
folly/ProducerConsumerQueue.h