aboutsummaryrefslogtreecommitdiff
path: root/book/en/src/by-example/tips/static_lifetimes.md
diff options
context:
space:
mode:
Diffstat (limited to 'book/en/src/by-example/tips/static_lifetimes.md')
-rw-r--r--book/en/src/by-example/tips/static_lifetimes.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/book/en/src/by-example/tips/static_lifetimes.md b/book/en/src/by-example/tips/static_lifetimes.md
new file mode 100644
index 0000000..b1fd606
--- /dev/null
+++ b/book/en/src/by-example/tips/static_lifetimes.md
@@ -0,0 +1,23 @@
+# 'static super-powers
+
+In `#[init]` and `#[idle]` `local` resources have `'static` lifetime.
+
+Useful when pre-allocating and/or splitting resources between tasks, drivers or some other object. This comes in handy when drivers, such as USB drivers, need to allocate memory and when using splittable data structures such as [`heapless::spsc::Queue`].
+
+In the following example two different tasks share a [`heapless::spsc::Queue`] for lock-free access to the shared queue.
+
+[`heapless::spsc::Queue`]: https://docs.rs/heapless/0.7.5/heapless/spsc/struct.Queue.html
+
+``` rust
+{{#include ../../../../../rtic/examples/static.rs}}
+```
+
+Running this program produces the expected output.
+
+``` console
+$ cargo run --target thumbv7m-none-eabi --example static
+```
+
+``` console
+{{#include ../../../../../rtic/ci/expected/static.run}}
+```