The official Arduino team this week announced the introduction of Arduino multitasking and is looking for help from the community by joining the discussion on GitHub. “We’re sharing our API proposal along with a fully working implementation as well” explain the Arduino team would like to know your thoughts on finalizing the new Arduino multitasking feature. With the ultimate goal of defining a standardized API that can be ported across all architectures.
“With the increased capabilities of Arduino and other microcontroller boards, including faster clocks or even multiple cores, the need to handle multiple tasks simultaneously arises more often than in the past. For instance, you often want to control motors, update a display and detect user interactions at the same time, or perform tasks that have different timing or wait for external events.
The traditional way to do this is to write non-blocking code so that the loop() function can run as fast as possible, updating state variables and calling the millis() function to ensure proper timing (see the “Blink without delay” example to learn more). This approach leads to bloated code, though, which is hard to debug and maintain, and also does not support multiple cores.
The Scheduler library already allows writing code in a cleaner way by splitting the sketch in multiple loop functions, so that each one can focus on a specific task. However, this approach is called cooperative multitasking, which means you still need to avoid blocking commands yourself. Also, it does not support multiple cores and even if it did it doesn’t protect you from accessing the same variables from multiple threads. Last but not least, it’s based on the traditional “busy loop” paradigm, which doesn’t really help for low power applications where you want to have threads rest as much as possible while waiting for an event or incoming data.”
Source : AB