cpu/atmega_common: Context switching race condition #8896
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)
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:
I will be submitting tests/thread_race after I finish writing this.
The text was updated successfully, but these errors were encountered: