diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-07-22 10:45:46 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-22 10:45:46 +0000 |
| commit | b6e8e37c3c543bebaec17a77760396c1e30afcdf (patch) | |
| tree | b9787cc52afe9b5aa03f5ba62610ed9a88878d45 /book | |
| parent | c62fd967d77ccf72c08ea720c21777e367ab4125 (diff) | |
| parent | a7ed040799f5d2c2a2a7021fef840a6717d88d44 (diff) | |
Merge #500
500: migration/0.5: cover #[lock_free] r=AfoHT a=japaric
I think this completes #488
Co-authored-by: Jorge Aparicio <jorge.aparicio@ferrous-systems.com>
Diffstat (limited to 'book')
| -rw-r--r-- | book/en/src/migration/migration_v5.md | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/book/en/src/migration/migration_v5.md b/book/en/src/migration/migration_v5.md index 210063b..24353d2 100644 --- a/book/en/src/migration/migration_v5.md +++ b/book/en/src/migration/migration_v5.md @@ -201,6 +201,49 @@ fn bar(cx: bar::Context) { Note that the performance does not change thanks to LLVM's optimizations which optimizes away unnecessary locks. +## Lock-free resource access + +In RTIC 0.5 resources shared by tasks running at the same priority could be accessed *without* the `lock` API. +This is still possible in 0.6: the `#[shared]` resource must be annotated with the field-level `#[lock_free]` attribute. + +v0.5 code: + +``` rust +struct Resources { + counter: u64, +} + +#[task(resources = [counter])] +fn a(cx: a::Context) { + *cx.resources.counter += 1; +} + +#[task(resources = [counter])] +fn b(cx: b::Context) { + *cx.resources.counter += 1; +} +``` + +v0.6 code: + +``` rust +#[shared] +struct Shared { + #[lock_free] + counter: u64, +} + +#[task(shared = [counter])] +fn a(cx: a::Context) { + *cx.shared.counter += 1; +} + +#[task(shared = [counter])] +fn b(cx: b::Context) { + *cx.shared.counter += 1; +} +``` + ## no `static mut` transform `static mut` variables are no longer transformed to safe `&'static mut` references. |
