Dynamic Threads

I'm looking for a library, that would allow for features alike those in Go, where you can start coroutines and communicate throw channels.

I've tried a lot of libraries so far, and one thing they all seem to have in common, is that they need all threads / tasks / coroutines (whatever you would like to call them) to be setup, or defined in the setup method, while I would want the ability to create threads on the fly, that is, after a Scheduler is started.

Do you guys know of any such library? Is it even possible to write such a library in for Arduino?

boginw:
I’m looking for a library, that would allow for features alike those in Go, where you can start coroutines and communicate throw channels.

In my opinion that style of programming is not appropriate for the small memory that is available in an Arduino. The Arduino only has a single microprocessor so it can only do one at a time.

If you wish to give the impression that multiple actions run in parallel look at the simple approach in Several Things at a Time

I reckon any system that is more complicated will just be wasting SRAM and CPU cycles.

…R

For multi-threaded applications I would switch to a processor with a real operating system. Perhaps a flavor of Raspberry Pi or Beagle Bone.

boginw:
I'm looking for a library, that would allow for features alike those in Go, where you can start coroutines and communicate throw channels.

I've tried a lot of libraries so far, and one thing they all seem to have in common, is that they need all threads / tasks / coroutines (whatever you would like to call them) to be setup, or defined in the setup method, while I would want the ability to create threads on the fly, that is, after a Scheduler is started.

Do you guys know of any such library? Is it even possible to write such a library in for Arduino?

I tend not to use a library, but to write my code in such a way that it kinda-sorta works like that. Have a look at the final section in my page ArduinoTheOOWay.html, the . The stuff there does not have provision for adding and removing runnable objects, but it's easy enough to see how it could be done. You'd maintain a linked list of runnables and have destructors to remove the runnables from the list.

Perhaps - have the runnable objects place themselves at the tail of the list when they are executed. Rather than running down the list of runnables, the scheduler would simply executes whatever item is at the head of the list. The double-indirect pointer trick can come in handy.

I find it a useful "several things at once" model for Arduino coding.

Many or most Arduino programs are linked to some physical process. A motor spinning or a sensor sensing. Those need predictable intervals. If the task scheduler is allowed to add new tasks during operation, how can you be sure that the time-critical tasks are done on time?

If you want multi-tasking, get a Raspberry Pi. The Pi Zero W can be had for under $20 - WiFi, USB, HDMI, SPI, I2C, I2S, Serial, PWM, built-in hi-res LCD driver, and much, much more. Runs Debian Linux with 512MB of RAM with a 1.3GHz 32-bit ARM. True multi-threading and a great development environment. You'll get the coding done in half the time, and it will be dead-reliable, providing you know what you're doing with multi-threading.

Regards,
Ray L.