mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
Add a remark about Sync
and Send
traits requirement for resources
This commit is contained in:
parent
ab26a1e185
commit
44f994dea2
1 changed files with 12 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue