Skip to content

should we add std::sync like primitives based on critical sections? #9

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

Closed
japaric opened this issue Nov 1, 2016 · 3 comments
Closed

Comments

@japaric
Copy link
Member

japaric commented Nov 1, 2016

See the mutex branch for an implementation of a mutex based on critical sections. And this PR for an example that uses that mutex to share state between the main thread and an interrupt.

The advantage of implementing them using critical sections is smaller code size, faster locking and that they don't require the LDREX or STREX instructions which are not available in the Cortex-M0(+).

If you have and can afford atomics then you should probably use the parking_lot crate.

cc @thejpster

@thejpster
Copy link
Contributor

I like this approach, but I think I'd prefer to follow the std::sync::Mutex API, or at least offer that as well.

let mut data = data.lock().unwrap();
*data += 1;

Could that work?

@japaric
Copy link
Member Author

japaric commented Nov 1, 2016

I prefer the more explicit scopes that closures provide and don't really like the release on drop mechanism because the guard can be "forgotten" using mem::forget but I'll sketch something and get back to you.

@japaric
Copy link
Member Author

japaric commented Mar 12, 2017

There's a Mutex in tree.

@japaric japaric closed this as completed Mar 12, 2017
adamgreig pushed a commit that referenced this issue Jan 12, 2022
Explicitly place non-suffixed sections
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

2 participants