Hacker News new | ask | show | jobs
by snops 2257 days ago
You can use Protothreads[1] for this which work on anything that runs C, as they are just using setjmp/longjmp.

I would recommend FreeRTOS instead, as it has proper prempetive scheduling, context switching and wide debugger support. It's actually only 4 files[2] so not very heavyweight in either memory or stuff to learn, and has decent abstractions for cross thread communication (queues etc). Then you can write continuous code and use preemption, rather than have to code everything as a state machine and co-operatively schedule, which is painful sometimes.

[1] http://dunkels.com/adam/pt/

[2] https://www.freertos.org/Creating-a-new-FreeRTOS-project.htm...