aboutsummaryrefslogtreecommitdiff
path: root/book
diff options
context:
space:
mode:
authorJorge Aparicio <jorge@japaric.io>2018-11-04 18:50:42 +0100
committerJorge Aparicio <jorge@japaric.io>2018-11-04 18:50:42 +0100
commit37a0692a0fe5d9b41b65728d496b6856a1152dcc (patch)
treebeb91d9c1caa0fb5e16e61236b6b92739766edd2 /book
parent16d473a9b6827aa7ffa9ce92e4e532eff9a091d2 (diff)
impl Mutex on all shared resources
document how to write generic code that operates on resources
Diffstat (limited to 'book')
-rw-r--r--book/src/by-example/tips.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/book/src/by-example/tips.md b/book/src/by-example/tips.md
index 0e3d47b..c163328 100644
--- a/book/src/by-example/tips.md
+++ b/book/src/by-example/tips.md
@@ -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