-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/atmega_common: Context switching race condition #8896
Description
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.