rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.29k stars 607 forks source link

Fine-tune the Ordering for num_senders #2833

Open wang384670111 opened 4 months ago

wang384670111 commented 4 months ago

https://github.com/rust-lang/futures-rs/blob/aafe554b02cbac19d396512b36bce8b688a18115/futures-channel/src/mpsc/mod.rs#L283

As mentioned in the comments, num_senders is used only for counting purposes, not for synchronizing access to other shared variables. While SeqCst guarantees the correctness of the program, it can also affect the performance. Therefore, using Relaxed is sufficient to maintain the correctness of the program without affecting its efficiency.

https://github.com/rust-lang/futures-rs/commit/ed3b268225c7c532a4b222adfe077c4e8ce0f24d Could you please explain the reasoning behind the need to switch to seqcst?