Timers and Reentrant code

At what level does the code in timer callbacks operate? Does it have to be reentrant to avoid race conditions? In other words, if I code a function to change a value and another to return the value, and I specify the change value function in a timer callback, and the value has multiple fields, can you guarantee that the change value function won’t be called by the timer and change part of the value while the return value function is running and result in an inconsistent return value?

Classical problem with concurrency, and usually controlled by semaphores or mutexs.

Timer callbacks run on a timer thread so they will run concurrently to any other threads with the exception of other registered timer handlers.

We are building out our threading API. There is low-level access to mutexes via the os_mutex_create() and similar HAL APIs. We have support for std::mutex in the works as well as a simpler Wiring API for mutexes, but if you’re in a hurry you can use the HAL API directly for now to create mutexes.