Skip to content

Commit

Permalink
Add notes to threads.md
Browse files Browse the repository at this point in the history
From the discussion in google#63.
  • Loading branch information
mgeisler authored and NoahDragon committed Jul 11, 2023
1 parent 03992f0 commit 585b61e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/concurrency/threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 585b61e

Please sign in to comment.