Let me introduce: Arduino-MOS, a ultra lightweight cooperative multitasking scheduler for Arduino devices
I know, there are a lot of schedulers available, but this one is different
MOS stands for Macro based Operating System.
It consists of only a few macros and can therefore be used on all Arduino devices.
It allows multitasking with blocking, cooperative tasks, but does not require additional memory.
So, give it a try...
The code with examples is available on github
This is difficult to actually use without some guidelines as the hidden goto's will require the programmer to save and restore any necessary context that might be needed.
You are right, there are great matches between the Protothreads and my solution.
Both go back to the article “Coroutines in C” from Simon Tatham (Coroutines in C)
It is fun that you mention a setjmp/longjmp implemented variant. That is actually the implementation method I used for a very simple scheduler:
This library allows a very simple method to start multiple setup() and loop() functions in the same sketch. The only requirement is that yield() or delay() are called at some point to context switch.
Please have a look. There are plenty of example sketches as some support classes for queues, events, semaphores, etc.