mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-02-09 20:23:37 +02:00
Merge pull request #117 from google/thread-speaker-notes
Add notes to threads.md
This commit is contained in:
commit
029aa8b139
@ -24,3 +24,22 @@ fn main() {
|
||||
* Threads are all daemon threads, the main thread does not wait for them.
|
||||
* Thread panics are independent of each other.
|
||||
* Panics can carry a payload, which can be unpacked with `downcast_ref`.
|
||||
|
||||
<details>
|
||||
|
||||
Key points:
|
||||
|
||||
* Notice that the thread is stopped before it reaches 10 — the main thread is
|
||||
not waiting.
|
||||
|
||||
* Use `let handle = thread::spawn(...)` and later `handle.join()` to wait for
|
||||
the thread to finish.
|
||||
|
||||
* Trigger a panic in the thread, notice how this doesn't affect `main`.
|
||||
|
||||
* Use the `Result` return value from `handle.join()` to get access to the panic
|
||||
payload. This is a good time to talk about [`Any`].
|
||||
|
||||
[`Any`]: https://doc.rust-lang.org/std/any/index.html
|
||||
|
||||
</details>
|
||||
|
Loading…
x
Reference in New Issue
Block a user