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 #63.
  • Loading branch information
mgeisler authored Jan 5, 2023
1 parent 6e8942e commit 82c0758
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/concurrency/threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ 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 type to talk about `Any`.

</details>

0 comments on commit 82c0758

Please sign in to comment.