diff options
| author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-04 18:58:45 +0000 |
|---|---|---|
| committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-04 18:58:45 +0000 |
| commit | 8a27efeaeb5483dc12370add4b3786bdd20a4973 (patch) | |
| tree | 00e10c34cc22f80aee45c51d945e31c237c74eeb /book | |
| parent | 16d473a9b6827aa7ffa9ce92e4e532eff9a091d2 (diff) | |
| parent | a2792182952c953aab2c442bb02ac1f2e4986e67 (diff) | |
Merge #99
99: impl Mutex on all shared resources r=japaric a=japaric
document how to write generic code that operates on resources
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Diffstat (limited to 'book')
| -rw-r--r-- | book/src/by-example/tips.md | 20 |
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 |
