rust/library/std/src
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
..
backtrace Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00
collections Added const_hash tracking issue id 2022-11-06 18:01:44 +01:00
env std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
error remove fn backtrace 2022-08-01 20:10:40 +00:00
f32 Semicolon after macro_rules definition. 2022-08-15 12:33:00 +02:00
f64 Semicolon after macro_rules definition. 2022-08-15 12:33:00 +02:00
ffi Guarantee try_reserve preserves the contents on error 2022-08-10 01:51:38 +09:00
fs Ignore hiberfil_sys test in CI 2022-07-18 15:06:07 +01:00
io Fix grammar in docs for std::io::Read 2022-10-24 01:06:34 -07:00
net Update mod.rs 2022-10-31 12:17:30 -04:00
num rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
os Make the whole std::os::wasi::io module stable. 2022-10-20 14:31:11 -07:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path make many std tests work in Miri 2022-08-18 18:07:39 -04:00
personality Interpret EH actions properly 2022-10-05 03:09:43 +01:00
prelude Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk 2022-11-12 12:02:50 +05:30
process Add test for issue #95178 2022-03-23 05:33:44 +00:00
sync Auto merge of #93563 - ibraheemdev:crossbeam-channel, r=Amanieu 2022-11-13 12:08:42 +00:00
sys std: fix double-free of mutex 2022-11-06 15:32:59 +01:00
sys_common std: remove lock wrappers in sys_common 2022-11-06 15:32:59 +01:00
thread avoid using channels in thread-local tests 2022-11-12 23:44:52 -05:00
time make many std tests work in Miri 2022-08-18 18:07:39 -04:00
alloc.rs Forbid mixing System with sytem allocator calls 2022-09-03 16:47:12 -05:00
ascii.rs Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
backtrace.rs std: use sync::Mutex for internal statics 2022-10-13 12:55:14 +02:00
env.rs env::temp_dir: fix a typo 2022-09-28 21:51:09 +02:00
error.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
f32.rs rustdoc: Add an example for round that is different from truncate 2022-11-06 23:05:16 +01:00
f64.rs rustdoc: Add an example for round that is different from truncate 2022-11-06 23:05:16 +01:00
fs.rs Do not alias for fs 2022-10-10 17:05:59 -07:00
keyword_docs.rs review feedback 2022-10-07 15:21:47 +02:00
lib.rs Test const Hash, fix nits 2022-11-08 17:39:40 +01:00
macros.rs stdio: Document no support for writing to non-blocking stdio/stderr 2022-09-07 14:22:57 +01:00
num.rs Add Saturating type (based on Wrapping type) 2021-08-10 19:27:01 +02:00
panic.rs Adding backtrace off option for fuchsia targets 2022-09-14 23:54:40 +00:00
panicking.rs Fix whitespace 2022-10-06 09:55:32 +02:00
path.rs Add basename and dirname aliases 2022-10-09 21:44:44 -07:00
personality.rs Move personality functions to std 2022-08-23 16:12:58 +08:00
primitive_docs.rs array docs - advertise how to get array from slice 2022-09-10 19:37:07 -07:00
process.rs Make diagnostic for unsatisfied Termination bounds more precise 2022-10-17 12:08:46 +02:00
rt.rs Change process spawning to inherit the parent's signal mask by default 2022-10-20 14:53:38 -07:00
time.rs Rollup merge of #102271 - lopopolo:lopopolo/stabilize-duration-try-from-secs-float, r=dtolnay 2022-10-24 19:32:26 +09:00