rust/library
bors afd7977c85 Auto merge of #93563 - ibraheemdev:crossbeam-channel, r=Amanieu
Merge crossbeam-channel into `std::sync::mpsc`

This PR imports the [`crossbeam-channel`](https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel#crossbeam-channel) crate into the standard library as a private module, `sync::mpmc`. `sync::mpsc` is now implemented as a thin wrapper around `sync::mpmc`. The primary purpose of this PR is to resolve https://github.com/rust-lang/rust/issues/39364. The public API intentionally remains the same.

The reason https://github.com/rust-lang/rust/issues/39364 has not been fixed in over 5 years is that the current channel is *incredibly* complex. It was written many years ago and has sat mostly untouched since. `crossbeam-channel` has become the most popular alternative on crates.io, amassing over 30 million downloads. While crossbeam's channel is also complex, like all fast concurrent data structures, it avoids some of the major issues with the current implementation around dynamic flavor upgrades. The new implementation decides on the datastructure to be used when the channel is created, and the channel retains that structure until it is dropped.

Replacing `sync::mpsc` with a simpler, less performant implementation has been discussed as an alternative. However, Rust touts itself as enabling *fearless concurrency*, and having the standard library feature a subpar implementation of a core concurrency primitive doesn't feel right. The argument is that slower is better than broken, but this PR shows that we can do better.

As mentioned before, the primary purpose of this PR is to fix https://github.com/rust-lang/rust/issues/39364, and so the public API intentionally remains the same. *After* that problem is fixed, the fact that `sync::mpmc` now exists makes it easier to fix the primary limitation of `mpsc`, the fact that it only supports a single consumer. spmc and mpmc are two other common concurrency patterns, and this change enables a path to deprecating `mpsc` and exposing a general `sync::channel` module that supports multiple consumers. It also implements other useful methods such as `send_timeout`. That said, exposing MPMC and other new functionality is mostly out of scope for this PR, and it would be helpful if discussion stays on topic :)

For what it's worth, the new implementation has also been shown to be more performant in [some basic benchmarks](https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel/benchmarks#results).

cc `@taiki-e`

r? rust-lang/libs
2022-11-13 12:08:42 +00:00
..
alloc Rollup merge of #104097 - RalfJung:miri-alloc-benches, r=thomcc 2022-11-08 20:40:50 +01:00
backtrace@07872f28cd Update backtrace 2022-09-02 16:09:58 -04:00
core Auto merge of #103913 - Neutron3529:patch-1, r=thomcc 2022-11-12 20:48:27 +00:00
panic_abort Remove std's transitive dependency on cfg-if 0.1 2022-11-02 18:01:20 -04:00
panic_unwind Remove std's transitive dependency on cfg-if 0.1 2022-11-02 18:01:20 -04:00
portable-simd separate the receiver from arguments in HIR under /clippy 2022-09-05 22:25:57 +09:00
proc_macro Stabilize proc_macro::Span::source_text 2022-10-18 17:13:41 +02:00
profiler_builtins Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rtstartup Remove custom frame info registration on i686-pc-windows-gnu 2022-08-23 16:12:58 +08:00
rustc-std-workspace-alloc Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rustc-std-workspace-core Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
rustc-std-workspace-std Switch all libraries to the 2021 edition 2021-12-23 19:03:47 +08:00
std Auto merge of #93563 - ibraheemdev:crossbeam-channel, r=Amanieu 2022-11-13 12:08:42 +00:00
stdarch@790411f93c library: update stdarch submodule 2022-10-13 09:41:16 +08:00
test Rollup merge of #103681 - RalfJung:libtest-thread, r=thomcc 2022-11-04 18:52:26 +01:00
unwind Remove linuxkernel targets 2022-11-05 12:30:28 -04:00