About multitasking\multithreading

A project log for Mayak

Handheld E-ink pocket PC on Arduino

SergeySergey 12/17/2017 at 14:400 Comments

In portable devices projects, it is very important to think about the correct architecture of the program code.

This project implies the execution of both a "main application task" - maps, a book reader, a weather screen, and "background tasks" - updating the weather forecast, swapping maps, etc. Usuall solution for this - is to use multi-threaded programming.
I like multithreaded programming, but in this case I think it is redundant and somewhat wasteful in terms of energy - because we have constant flow context switching (which is a relatively cheap operation? but in the context of time it has the property of accumulating).

An alternative to multithreaded programming in the context of multitasking is the cooperative multitask approach, where each task keeps the thread of execution exactly as long as it needs it.

Obvious advantages:

- It's easy to realize "idle" sleep state.

- We do not need to sync threads. 

- We do not spend time on switching thread context ( of course we spend some ticks on magic with pointers)

- Execution of the program flow becomes linear and easier to debug

Reasoning in this way, I chose cooperative multitasking for this project.