Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Send shared resource container for thumbv6m-none-eabi target #800

Open
smmoosavi opened this issue Sep 11, 2023 · 6 comments
Open

Comments

@smmoosavi
Copy link

Hi,

I want to define a shareable mutable container like Rc<RefCell> and store that in the #[shared] struct. But Rc<RefCell> is not Send.

Types of #[shared] resources have to be Send.

Then I tried to use the Arbiter struct. It's not Clone so I have to wrap it in Arc. Arc<Arbiter> is working as expected. but Arc is not Implemented for the thumbv6m-none-eabi target.

use alloc::sync::Arc;
//         ^^^^ could not find `sync` in `alloc`

I also tried &Arbiter, but it forced me to have a lifetime for my struct. which cause lifetime error when used by Mutex:

assert_eq!(mtx.lock(|option| option.wait_for_value()).await, 1);
//                   ------- ^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
//                   |     |
//                   |     return type of closure is async_option::wait_for_value_future::WaitForValueFuture<'2, i32>
//                   has type `&'1 mut async_option::AsyncOption<i32>`

What is the best alternative for the Rc<RefCell> for the thumbv6m-none-eabi target?

I created a sample repo with multiple implementations.

@korken89
Copy link
Collaborator

Hi,

The only way to have non-Send is in a resource in an priority = 0 task.
If you want to store something (where the inner value is Send), Arbiter is a good choice.
I'm not sure I understand your usecase good enough to give any better advice.

Hope that helps!

@smmoosavi
Copy link
Author

I'm not sure I understand your usecase good enough to give any better advice.

We need access to the same Arbiter from multiple tasks. The Arc struct was the perfect solution for us, But it does not exist in thumbv6m-none-eabi

@korken89
Copy link
Collaborator

Hi,

The rtic_sync::arbiter::Arbiter should work from multiple tasks, it is Sync.
So either share it via a static or an immutable resource would be my recommendation.
Arc is not needed for Arbiter.

@AfoHT
Copy link
Contributor

AfoHT commented Oct 4, 2023

Did you figure this out by using the Arbiter?

@smmoosavi
Copy link
Author

smmoosavi commented Oct 7, 2023

@AfoHT

No, @korken89's recommendation is more about how to avoid the problem. Sometimes I have a non-static struct that needs one simple field and one shared field, so it can't be either static or immutable

I add the ValueContainer (rc version) example to the repo (arbiter version which have same life-time error)

@smmoosavi
Copy link
Author

I found a portable-atomic-util crate that provides the Arc type for
thumbv6m-none-eabi. It is part of portable atomic and uses portable-atomic crate internally. rtic use
atomic-polyfill which is deprecated and encourages the use portable-atomic
instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants