diff options
| author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-03 16:31:11 +0000 |
|---|---|---|
| committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-03 16:31:11 +0000 |
| commit | 777765e522949ebf84d05d4db075132172d81494 (patch) | |
| tree | 41bc00739da8f832eb5ba68ef99ec8b9d06111a4 /examples/not-send.rs | |
| parent | 653338e7997a0cdc5deaed98b1bb5f60006717ed (diff) | |
| parent | 3a867e70c3b1afc4943ec597e4f188432fba5a8b (diff) | |
Merge #97
97: v0.4.0 r=japaric a=japaric
closes #32
closes #33
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
Diffstat (limited to 'examples/not-send.rs')
| -rw-r--r-- | examples/not-send.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/not-send.rs b/examples/not-send.rs new file mode 100644 index 0000000..be78c33 --- /dev/null +++ b/examples/not-send.rs @@ -0,0 +1,58 @@ +//! `examples/not-send.rs` + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +extern crate panic_halt; + +use core::marker::PhantomData; + +use cortex_m_semihosting::debug; +use rtfm::app; + +pub struct NotSend { + _0: PhantomData<*const ()>, +} + +#[app(device = lm3s6965)] +const APP: () = { + static mut SHARED: Option<NotSend> = None; + + #[init(spawn = [baz, quux])] + fn init() { + spawn.baz().unwrap(); + spawn.quux().unwrap(); + } + + #[task(spawn = [bar])] + fn foo() { + // scenario 1: message passed to task that runs at the same priority + spawn.bar(NotSend { _0: PhantomData }).ok(); + } + + #[task] + fn bar(_x: NotSend) { + // scenario 1 + } + + #[task(priority = 2, resources = [SHARED])] + fn baz() { + // scenario 2: resource shared between tasks that run at the same priority + *resources.SHARED = Some(NotSend { _0: PhantomData }); + } + + #[task(priority = 2, resources = [SHARED])] + fn quux() { + // scenario 2 + let _not_send = resources.SHARED.take().unwrap(); + + debug::exit(debug::EXIT_SUCCESS); + } + + extern "C" { + fn UART0(); + fn UART1(); + } +}; |
