rust/library/std/src
Yuki Okushi dda9d0589f
Rollup merge of #82943 - kornelski:threadstdio, r=joshtriplett
Demonstrate best practice for feeding stdin of a child processes

Documentation change.

It's possible to create a deadlock with stdin/stdout I/O on a single thread:

* the child process may fill its stdout buffer, and have to wait for the parent process to read it,
* but the parent process may be waiting until its stdin write finishes before reading the stdout.

Therefore, the parent process should use separate threads for writing and reading.

These examples are not deadlocking in practice, because they use short strings, but I think it's better to demonstrate code that works even for long writes. The problem is non-obvious and tricky to debug (it seems that even libstd has a similar issue: #45572).

This also demonstrates how to use stdio with threads: it's not obvious that `.take()` can be used to avoid fighting with the borrow checker.

I've checked that the modified examples run fine.
2021-03-14 13:07:34 +09:00
..
backtrace Add Frames iterator for Backtrace 2021-01-23 11:56:33 -06:00
collections Rollup merge of #82764 - m-ou-se:map-try-insert, r=Amanieu 2021-03-05 10:57:22 +01:00
env std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
error std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
f32 std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
f64 std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
ffi Rollup merge of #82121 - lopopolo:pathbuf-osstring-extend, r=joshtriplett 2021-03-14 13:07:28 +09:00
fs std: Fix test got_symlink_permission on Windows 2020-11-16 21:09:26 +03:00
io Generalize Write impl for Vec<u8> to Vec<u8, A> 2021-03-07 16:22:53 +01:00
lazy Upgrade wasm32 image to Ubuntu 20.04 2021-02-06 13:05:56 +01:00
memchr std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
net add #[inline] to all the public IpAddr functions 2021-02-03 10:53:25 -05:00
num rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
os Rollup merge of #82712 - CDirkx:cfg-target_os, r=dtolnay 2021-03-03 16:27:47 +09:00
panic review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
path Refactor parse_prefix on Windows 2020-11-07 16:15:48 +01:00
prelude Rollup merge of #82217 - m-ou-se:edition-prelude, r=nikomatsakis 2021-03-10 17:55:38 +01:00
process std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
sync Rollup merge of #82578 - camsteffen:diag-items, r=oli-obk 2021-03-01 11:25:07 -05:00
sys Rollup merge of #82804 - alexcrichton:fix-wasi, r=pnkfelix 2021-03-14 13:07:33 +09:00
sys_common Revert "use RWlock when accessing os::env #81850" 2021-03-07 11:32:42 -08:00
thread Rollup merge of #79849 - Digital-Chaos:sleep-zero, r=m-ou-se 2021-02-10 12:24:18 +09:00
time Duration::zero() -> Duration::ZERO 2020-10-21 20:44:03 -07:00
alloc.rs Fix safety comment 2021-01-07 09:13:21 +01:00
ascii.rs Convert many files to intra-doc links 2020-09-02 17:37:40 -04:00
backtrace.rs Add Frames iterator for Backtrace 2021-01-23 11:56:33 -06:00
env.rs Document security implications of std::env::temp_dir 2021-01-20 11:24:47 -08:00
error.rs Add tracking issue for map_try_insert. 2021-03-04 16:54:28 +01:00
f32.rs doc: cube root, not cubic root 2021-02-26 19:03:44 +01:00
f64.rs doc: cube root, not cubic root 2021-02-26 19:03:44 +01:00
fs.rs Add doc aliases for "delete" 2021-01-31 11:07:37 +01:00
keyword_docs.rs Convert primitives to use intra-doc links 2021-02-25 20:31:53 -05:00
lazy.rs Clarify that SyncOnceCell::set blocks. 2021-02-28 12:57:38 -08:00
lib.rs Rollup merge of #82217 - m-ou-se:edition-prelude, r=nikomatsakis 2021-03-10 17:55:38 +01:00
macros.rs Use #[doc = include_str!()] in std 2021-02-23 15:54:55 +01:00
memchr.rs std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
num.rs std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
panic.rs Fixed minor typo in catch_unwind docs 2021-02-13 16:59:06 +01:00
panicking.rs fix another comment, and make __rust_start_panic code a bit more semantically clear 2020-12-25 23:37:27 +01:00
path.rs Rollup merge of #82128 - anall:feature/add_diagnostic_items, r=davidtwco 2021-02-23 02:51:51 +01:00
primitive_docs.rs Convert primitives to use intra-doc links 2021-02-25 20:31:53 -05:00
process.rs Rollup merge of #82943 - kornelski:threadstdio, r=joshtriplett 2021-03-14 13:07:34 +09:00
rt.rs Prevent __rust_begin_short_backtrace frames from being tail-call optimised away 2020-08-07 19:31:25 +01:00
time.rs Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00