Multithreading with Arduino

Hey! Does Arduino support multi-threading in any way? If the answer to the above question is in the negative, is there any method to support a pseudo-multithreading process?

No, one core means one process at a time.

But if you avoid using any blocking code you can make things run so fast that they appear to be happening at the same time.

See this thread: Demonstration code for several things at one time.

You might want to look here:

https://forum.arduino.cc/index.php?topic=150299.0

https://forum.arduino.cc/index.php?topic=430332.0

Cosa's framework has a Scheduler.. which helps you multitask.

But if you avoid using any blocking code you can make things run so fast that they appear to be happening at the same time.

I am aware of the “blink without delay” example, albeit it doesn’t work in my case.
Thanks for chipping in.

adeelshams: I am aware of the "blink without delay" example, albeit it doesn't work in my case.

We're all ears to hear why not ;)

As mentioned above, a non-blocking code such as the famous "blinking without delay" may be an option.

Another option is a Direct Memory Address controller which gives you the opportunity to (nearly) run several process at a time with a single core because a DMA requires very few CPU load, and you can even run several DMA process at a time. Arduino DUE and ZERRO have a DMA feature.

You could also consider preemptive multitasking before multithreading. For this option, have a look at this thread:

https://forum.arduino.cc/index.php?topic=318084.0

For multithreading with a multicore uc, you might consider an arduino compatible Shieldbuddy with an Infineon tricore TC275 : same board pin arrangement as an Arduino DUE.

https://www.ehitex.de/en/starter-kits/for-aurix/2535/hitex-shieldbuddytc275-aurix-powered-arduino-uno-r3-hardware-compatible-platform

manor_royal: We're all ears to hear why not ;)

Me too. Using the BWoD technique is simple to implement and has a very low overhead.

...R

So ... It depends on exactly what you mean by "multi-threading." "Thread" used to mean the same thing as "process" or "task", and all you needed was some sort of operating system that supported that, to have multiple threads/processes/tasks. There are a couple of these for Arduino; someone already mentioned COSA. There's also freeRTOS, ChibiOS, and some others. They tend not to be very useful on AVRs because the ratio of per-process context (~35 bytes plus stack) to total RAM (2k on an UNO) is not very favorable. They'll work better on the ARM-based Arduinos. But they DO WORK. (By the time you get to an ARM, you have a broader choice of OSes as well. mBedOS and Zephyr are two "significant" OSes that will run on Due or Zero class hardware.

Then Intel came along and started marketing processors with "HyperThreading" - a sort of multi-tasking at a lower level where a single CPU core could pretend to be two CPUs, and run some of the multi-core software, algorithms, and trouble-making stuff that was around. None of the current Arduinos have that sort of hardware; they just have one core with a single execution stream...