From 5805a05fac2fc5824009586b3ee2fd36dc27fbbf Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 22 Jul 2021 09:17:39 +0200 Subject: book/resources: rm #[task_local] mention; add #[lock_free] example the #[task_local] attribute was removed --- book/en/src/by-example/resources.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'book') diff --git a/book/en/src/by-example/resources.md b/book/en/src/by-example/resources.md index 11ba4ce..855cde9 100644 --- a/book/en/src/by-example/resources.md +++ b/book/en/src/by-example/resources.md @@ -97,11 +97,15 @@ $ cargo run --example only-shared-access ## Lock-free resource access of mutable resources -There exists two other options dealing with resources - -* `#[lock_free]`: there might be several tasks with the same priority - accessing the resource without critical section. Since tasks with the - same priority never can preempt another task on the same priority - this is safe. -* `#[task_local]`: there must be only one task using this resource, - similar to a `static mut` task local resource, but (optionally) set-up by init. +A critical section is *not* required to access a `#[shared]` resource that's only accessed by tasks running at the *same* priority. +In this case, you can opt out of the `lock` API by adding the `#[lock_free]` field-level attribute to the resource declaration (see example below). +Note that this is merely a convenience: if you do use the `lock` API, at runtime the framework will *not* produce a critical section. + +``` rust +{{#include ../../../../examples/lock-free.rs}} +``` + +``` console +$ cargo run --example lock-free +{{#include ../../../../ci/expected/lock-free.run}} +``` -- cgit v1.2.3