Arduino_LED_Matrix.h
's timer has a data race (missing volatile
) which breaks animations
#418
Labels
topic: code
Related to content of the project itself
type: imperfection
Perceived defect in any part of project
The
Arduino_LED_Matrix
class uses aFspTimer
in order to advance its animations. The timer has this callback installed:https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/Arduino_LED_Matrix/src/Arduino_LED_Matrix.h#L345
The callback touches a bunch of data fields of the
Arduino_LED_Matrix
object (that installed the callback). The object is indeed passed as the context argument (last parameter of https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/Arduino_LED_Matrix/src/Arduino_LED_Matrix.h#L182 ).The problem is that these fields are not marked
volatile
.FspTimer
uses ISR to manage the timer, and any non-local data touched by ISR callbacks must be markedvolatile
, as per https://www.arduino.cc/reference/cs/language/functions/external-interrupts/attachinterrupt/Since the mark is not there, there's a data race. I am able to make animations block or behave erratically by simply changing the currently running animation. Most data members need
volatile
:The text was updated successfully, but these errors were encountered: