rollup merge of #23902: freebroccolo/master

This commit is contained in:
Alex Crichton 2015-03-31 15:58:57 -07:00
commit 82889f709e

View File

@ -280,13 +280,15 @@ it returns an `Result<T, E>`, and because this is just an example, we `unwrap()`
it to get a reference to the data. Real code would have more robust error handling it to get a reference to the data. Real code would have more robust error handling
here. We're then free to mutate it, since we have the lock. here. We're then free to mutate it, since we have the lock.
This timer bit is a bit awkward, however. We have picked a reasonable amount of Lastly, while the threads are running, we wait on a short timer. But
time to wait, but it's entirely possible that we've picked too high, and that this is not ideal: we may have picked a reasonable amount of time to
we could be taking less time. It's also possible that we've picked too low, wait but it's more likely we'll either be waiting longer than
and that we aren't actually finishing this computation. necessary or not long enough, depending on just how much time the
threads actually take to finish computing when the program runs.
Rust's standard library provides a few more mechanisms for two threads to A more precise alternative to the timer would be to use one of the
synchronize with each other. Let's talk about one: channels. mechanisms provided by the Rust standard library for synchronizing
threads with each other. Let's talk about one of them: channels.
## Channels ## Channels