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
Contact:

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

Postby Lele » Sun Oct 20, 2013 7:59 am

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/~sgtatham/coroutines.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

Postby sethu_jangala » Mon Oct 21, 2013 9:37 am

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: 843
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Postby segher » Mon Oct 21, 2013 9:03 pm

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: 99
Joined: Sun Mar 06, 2011 11:39 pm

Postby TSC » Tue Oct 22, 2013 1:07 am

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
Contact:

Postby Lele » Tue Oct 22, 2013 6:56 am

Segher is right: the first set of macro is not for reentrant/recursive functions.
But there is also a set which stores local variables

Who is online

Users browsing this forum: No registered users and 9 guests