diff options
author | 2022-02-11 08:41:53 +0000 | |
---|---|---|
committer | 2022-02-11 08:41:53 +0000 | |
commit | 5a186feb16b2800d86a4861084207e720a442ee3 (patch) | |
tree | e99e0c6e0a98183fe0e50baa3808f932ed5e5e9a | |
parent | a98058c2a0bafc4f5f53e20538bff1dc57a8c944 (diff) | |
parent | 44f994dea2d825e77b4c89738cff4ab5c8c08ef2 (diff) | |
download | rtic-5a186feb16b2800d86a4861084207e720a442ee3.tar.gz rtic-5a186feb16b2800d86a4861084207e720a442ee3.tar.zst rtic-5a186feb16b2800d86a4861084207e720a442ee3.zip |
Merge #603
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>
-rw-r--r-- | book/en/src/by-example/resources.md | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/book/en/src/by-example/resources.md b/book/en/src/by-example/resources.md index 64269132..9d51d6c9 100644 --- a/book/en/src/by-example/resources.md +++ b/book/en/src/by-example/resources.md @@ -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 |