Are timers preemptive?

If I set up a software timer, can it interrupt running application code arbitrarily? Only during delay()s?

How do the various SYSTEM_MODE()s affect this?

Basically, I’m trying to determine what level of synchronization I need between a timer which produces some data, and an application routine in loop() which consumes the same.

Software Timers are run on a dedicated thread, so one timer will not “interrupt” another timer, but timers can “interrupt” loop()

The FreeRTOS threads get a 1ms time slice each and the switch can happen “any” time (unless sync constructs prevent a switch - see https://docs.particle.io/reference/firmware/photon/#task-switching)

2 Likes

Great! So protection of concurrent accesses should be done with SINGLE_THREADED_BLOCK(), I take it?

1 Like

@AustinGlaser, yes, that is the way to go since mutexes are not exposed on the user API.

1 Like