mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 06:15:45 +01:00
impl Mutex on all shared resources
document how to write generic code that operates on resources
This commit is contained in:
parent
16d473a9b6
commit
37a0692a0f
11 changed files with 322 additions and 104 deletions
|
|
@ -1,5 +1,25 @@
|
|||
# Tips & tricks
|
||||
|
||||
## Generics
|
||||
|
||||
Resources shared between two or more tasks implement the `Mutex` trait in *all*
|
||||
contexts, even on those where a critical section is not required to access the
|
||||
data. This lets you easily write generic code that operates on resources and can
|
||||
be called from different tasks. Here's one such example:
|
||||
|
||||
``` rust
|
||||
{{#include ../../../examples/generics.rs}}
|
||||
```
|
||||
|
||||
``` console
|
||||
$ cargo run --example generics
|
||||
{{#include ../../../ci/expected/generics.run}}```
|
||||
|
||||
This also lets you change the static priorities of tasks without having to
|
||||
rewrite code. If you consistently use `lock`s to access the data behind shared
|
||||
resources then your code will continue to compile when you change the priority
|
||||
of tasks.
|
||||
|
||||
## Running tasks from RAM
|
||||
|
||||
The main goal of moving the specification of RTFM applications to attributes in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue