1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-24 01:36:44 +02:00

Update Concurrency course with times (#2007)

As I mentioned in #1536:

* Break into segments at approximately the places @fw-immunant put
breaks
 * Move all of the files into `src/concurrency`
 * Add timings and segment/session metadata so course outlines appear

There's room for more work here, including some additional feedback from
@fw-immunant after the session I observed, but let's do one step at a
time :)
This commit is contained in:
Dustin J. Mitchell
2024-04-23 09:26:41 -04:00
committed by GitHub
parent a03b7e68e5
commit face5af783
58 changed files with 385 additions and 246 deletions

View File

@ -1,3 +1,7 @@
---
minutes: 6
---
# Examples
## `Send + Sync`

View File

@ -0,0 +1,29 @@
---
minutes: 2
---
# Marker Traits
How does Rust know to forbid shared access across threads? The answer is in two
traits:
- [`Send`][1]: a type `T` is `Send` if it is safe to move a `T` across a thread
boundary.
- [`Sync`][2]: a type `T` is `Sync` if it is safe to move a `&T` across a thread
boundary.
`Send` and `Sync` are [unsafe traits][3]. The compiler will automatically derive
them for your types as long as they only contain `Send` and `Sync` types. You
can also implement them manually when you know it is valid.
[1]: https://doc.rust-lang.org/std/marker/trait.Send.html
[2]: https://doc.rust-lang.org/std/marker/trait.Sync.html
[3]: ../unsafe/unsafe-traits.md
<details>
- One can think of these traits as markers that the type has certain
thread-safety properties.
- They can be used in the generic constraints as normal traits.
</details>

View File

@ -1,3 +1,7 @@
---
minutes: 2
---
# `Send`
> A type `T` is [`Send`][1] if it is safe to move a `T` value to another thread.

View File

@ -1,3 +1,7 @@
---
minutes: 2
---
# `Sync`
> A type `T` is [`Sync`][1] if it is safe to access a `T` value from multiple