Skip to content

Commit

Permalink
Mention scoped threads
Browse files Browse the repository at this point in the history
  • Loading branch information
ChayimFriedman2 committed Jan 10, 2024
1 parent 34520cf commit ed365af
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/threading/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,17 @@ A few things to note:
`data` must be copied or cloned (depending on what the type of the value
supports).

Since Rust 1.63.0, it is possible to use [scoped threads] to use non-static data
(including references to not-`move`d values) in threads. The trade-off is that
since the data must remain alive until the thread's end, it is forcibly joined
by the end of the scope.

- Rust thread can return values, like tasks in C#, which becomes the return
value of the `join` method.

- It is possible to also pass data to the C# thread via a closure, like the
Rust example, but the C# version does not need to worry about ownership
since the memory behind the data will be reclaimed by the GC once no one is
referencing it anymore.

[scoped threads]: https://doc.rust-lang.org/stable/std/thread/fn.scope.html

0 comments on commit ed365af

Please sign in to comment.