Page 1 of 1

Coroutines: a "must know" for programmers (according to me)

Posted: Sun Oct 20, 2013 7:59 am
by Lele
Some years ago I found a document by Simon Tatham with a coroutine.h source conaining a set C macros to make cooperative routines.
http://www.chiark.greenend.org.uk/~sgta ... tines.html
I became a fan of those macros that let you make a sort of multi tasking. No need to waste precious real time deterministic xcore threads to run low priority tasks.
Very smart the way Duff's device is used.

Also I suggest a reading at protothread:
http://dunkels.com/adam/pt/about.html

Re: Coroutines: a "must know" for programmers (according to

Posted: Mon Oct 21, 2013 9:37 am
by sethu_jangala
Thank you for sharing the information. Hopefully, the other members in the community also find the information useful.

Sethu.

Re: Coroutines: a "must know" for programmers (according to

Posted: Mon Oct 21, 2013 9:03 pm
by segher
These routines store all state globally, there can be only
one instance running consecutively; these aren't coroutines.
You could pass in a pointer to a struct to store the state in,
destroying all the neat syntactic sugar: but that does show
what you really have, namely an explicit state machine.

Don't the latest XC additions support cooperative threading
btw? I haven't more than glanced at it I'm afraid :-(

Re: Coroutines: a "must know" for programmers (according to

Posted: Tue Oct 22, 2013 1:07 am
by TSC
Very interesting stuff Lele.

I think the XC addition segher mentioned is combinable functions. I haven't used that feature yet either, but it does sound similar to the information Lele linked to.

Re: Coroutines: a "must know" for programmers (according to

Posted: Tue Oct 22, 2013 6:56 am
by Lele
Segher is right: the first set of macro is not for reentrant/recursive functions.
But there is also a set which stores local variables