crossbeam
crossbeam copied to clipboard
Fine-tune the ordering for received
https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/flavors/at.rs#L51 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/flavors/at.rs#L89 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/flavors/at.rs#L120
I believe that using a Release operation in swap and an Acquire operation in load can effectively synchronize with the writing of the message to memory. Using SeqCst is not necessary in this context.
(glad to make a pull request if this seems sensible)
Similarly, in wake.rs, using SeqCst is unnecessary. Using Acquire/Release would be sufficient.
https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/waker.rs#L200-L203 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/waker.rs#L211-L214 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/waker.rs#L221 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/waker.rs#L223 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/waker.rs#L226-L229 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/waker.rs#L239-L242 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/waker.rs#L250-L253 https://github.com/crossbeam-rs/crossbeam/blob/95d0bd04624473b546826fdb97f10abe849443e4/crossbeam-channel/src/waker.rs#L261-L264
The SeqCst throughout crossbeam-channel is necessary to establish a total order between send/recv and is_empty. Without it the optimistic check in https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-channel/src/waker.rs#L222 would be incoherent.