Fix race condition when stopping blinking #49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Was running into couple different race conditions when calling blink then trying to set the LED back to on. Minimal program to recreate bug :
Two race conditions I was hitting:
led.on()
called while blinker is running; it sets theblinking
tofalse
then turns the device to on but by the time blinker wakes from sleep the device is on and it then turns it off again before bailing from its loopled.on()
between the on/off sleep interval the blinker will then turn it offThe first is remediated by removing
device.lock().unwrap().off();
from theif !blinking.load(Ordering::SeqCst){ .. }
condition and just relying on who ever callsself.stop()
to set the final state it wants.The second remediated by adding the
if !blinking.load(Ordering::SeqCst){ .. }
check between sleeps to avoid clobbering the state whoever called stop set (feel there might be cleaner way to do this part 😅).