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

Race conditions #219

Open
FrozenDroid opened this issue Apr 26, 2021 · 3 comments
Open

Race conditions #219

FrozenDroid opened this issue Apr 26, 2021 · 3 comments

Comments

@FrozenDroid
Copy link
Contributor

FrozenDroid commented Apr 26, 2021

Hi. We've been trying to get our code to run with opt-levels above 1, but we've been having some issues.
Turns out there's some issues where code has been written specifically to work with opt-level 1 or less.
One example is https://github.com/stm32-rs/stm32l4xx-hal/blob/master/src/timer.rs#L60
Here, if you use opt-level 2 for example, this line will be executed before the update event flag is even set. Thus, the interrupt will be constantly pending because the clearing happens too soon.
I will see if I can whip up a solution, but if anyone else wants to have their hand at fixing it, that would be great. I'll let you know when I start working on a solution.

@korken89
Copy link
Collaborator

Thanks for reporting!

Seems odd, the register access has volatile semantics so they should not reorder.
Have you had a look at the generated assembly?

@FrozenDroid
Copy link
Contributor Author

Volatile access is not relevant here. Loading the prescaler value actually just takes a while, and you're not waiting till the update flag is actually set. So you clear it even though it's not set.

@korken89
Copy link
Collaborator

korken89 commented Jun 1, 2021

Ah, I see.
You seem to understand how the timer works in this case, could you provide a patch for this issue?

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