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

Off topic discussions that do not fit into any of the above can go here. Please keep it clean and respectful.
User avatar
Lele
Active Member
Posts: 52
Joined: Mon Oct 31, 2011 4:08 pm

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

Post 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


User avatar
sethu_jangala
XCore Expert
Posts: 589
Joined: Wed Feb 29, 2012 10:03 am

Post by sethu_jangala »

Thank you for sharing the information. Hopefully, the other members in the community also find the information useful.

Sethu.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post 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 :-(
User avatar
TSC
Experienced Member
Posts: 103
Joined: Sun Mar 06, 2011 11:39 pm

Post 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.
User avatar
Lele
Active Member
Posts: 52
Joined: Mon Oct 31, 2011 4:08 pm

Post 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