by conurus » Sun Jun 09, 2013 9:24 am
Thanks for your reply, but I have already decided cocoOS is not what I need.
I was trying to do the classical producer-consumer pattern. I could either
1, use an RTOS, which would consume much precious resource, or
2, rewrite one side as a state machine, which would make the code ugly, unreadable and unmaintainable, or
3, use coroutines.
I have to wait within deep-nested function calls, or else the code will have to be restructured and would look just as ugly as if I have chosen option #2. However, an observation can be made that I don't have to restructure both the consumer and the producer. Only one side needs to be turned into a state machine or a coroutine (with a C-macro based implementation, the two are basically the same thing). So long as one side doesn't need to wait within deep-nested function call like my previous example, it could be turned into a coroutine using C macros. So long story short I don't need the whole OS, but only the macros to implement a coroutine.
I think all of the limitations we see are the limitations of the C language itself, but not that of the coroutine concept. Makes me wonder why we always program in C on microcontrollers. There may be other programming languages better suited for the job.