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.