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

cpu/atmega_common: Context switching race condition #8896

Closed
ZetaR60 opened this issue Apr 7, 2018 · 0 comments
Closed

cpu/atmega_common: Context switching race condition #8896

ZetaR60 opened this issue Apr 7, 2018 · 0 comments
Assignees
Labels
Platform: AVR Platform: This PR/issue effects AVR-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Comments

@ZetaR60
Copy link
Contributor

ZetaR60 commented Apr 7, 2018

On the ATmega there is a race condition where instructions after AVR_CONTEXT_SWAP_TRIGGER are executed before the context swap actually occurs. In my testing it seems that the thread_yield_higher function call has enough delay that instructions after it are not executed before the swap. However, this may change under environmental conditions that change clock rate or propagation delays such as: clock frequency (used 8MHz), voltage (used 3.3V), parasitics attached to the pin (appears to not be significant), temperature, part variations, and so forth.

To reproduce: Run an instruction immediately after AVR_CONTEXT_SWAP_TRIGGER, and within another thread, that both set conflicting states. Test for which state was actually set first.

Expected results: Conditions changed in second thread occurs before any instructions placed after AVR_CONTEXT_SWAP_TRIGGER.

Actual results: At least one instruction after AVR_CONTEXT_SWAP_TRIGGER is executed before context swap occurs.

Versions:

  • avr-gcc 7.2.0
  • avr-libc 2.0.0
  • mega-xplained board

I will be submitting tests/thread_race after I finish writing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: AVR Platform: This PR/issue effects AVR-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants