603: Add a remark about `Sync` and `Send` traits requirement for resources r=AfoHT a=Glaeqen



Co-authored-by: Gabriel Górski <glaeqen@gmail.com>
This commit is contained in:
bors[bot] 2022-02-11 08:41:53 +00:00 committed by GitHub
commit 5a186feb16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,11 @@ task.
Thus, a task `#[local]` resource can only be accessed by one singular task.
Attempting to assign the same `#[local]` resource to more than one task is a compile-time error.
Types of `#[local]` resources must implement [`Send`] trait as they are being sent from `init`
to target task and thus crossing the thread boundary.
[`Send`]: https://doc.rust-lang.org/stable/core/marker/trait.Send.html
The example application shown below contains two tasks where each task has access to its own
`#[local]` resource, plus that the `idle` task has its own `#[local]` as well.
@ -51,6 +56,11 @@ A special use-case of local resources are the ones specified directly in the res
initialized in `#[init]`.
Moreover, local resources in `#[init]` and `#[idle]` have `'static` lifetimes, this is safe since both are not re-entrant.
Types of `#[task(local = [..])]` resources have to be neither [`Send`] nor [`Sync`] as they
are not crossing any thread boundary.
[`Sync`]: https://doc.rust-lang.org/stable/core/marker/trait.Sync.html
In the example below the different uses and lifetimes are shown:
``` rust
@ -95,6 +105,8 @@ $ cargo run --target thumbv7m-none-eabi --example lock
{{#include ../../../../ci/expected/lock.run}}
```
Types of `#[shared]` resources have to be both [`Send`] and [`Sync`].
## Multi-lock
As an extension to `lock`, and to reduce rightward drift, locks can be taken as tuples. The