Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"03-12-11 - C Coroutines with Stack"

5 Comments -

1 – 5 of 5
Anonymous Anonymous said...

Does that work on a machine with callee-saved registers? (I.e. does that work on anything except x86?)

March 12, 2011 at 8:05 PM

Blogger Thatcher Ulrich said...

Lua has a native coroutine patch that allegedly works on Windiws, OSX, BSD, and Linux. http://coco.luajit.org/ I see code in the patch for x86, x64, PPC, ARM, MIPS, SPARC and "LP64" (Itanic?). I think you can just pull the C macros out of it and use them, and discard the Lua-specific stuff.

It looks like the windows code uses Fibers. The knock on Fibers that I've heard is that some system calls are not compatible with Fibers, so you have to be careful, or bad things happen. Hearsay, not based on firsthand knowledge, I don't remember details.

March 18, 2011 at 4:09 PM

Blogger Shelwien said...

Did you see that - http://stackoverflow.com/questions/4352451/coroutine-demo-source-2/4352706#4352706 ?

April 3, 2011 at 2:53 PM

Blogger cbloom said...

Hmm.. that looks very similar to the broken one I wrote. Broken in the sense that it's not remotely portable. It's pretty easy to make this work on any one compiler/CPU.

Really not worth bothering with when you can just use member variables.

April 3, 2011 at 2:58 PM

Blogger Shelwien said...

Well, my version is actually portable - I tested it with MSC/IntelC/gcc linux/windows x86/x64/arm. Also it makes sense as a speed optimization (easy to add buffering to bytewise processing loop), and _not_ using any globals/structure fields is a good speed optimization too.
For example, compare http://nishi.dreamhosters.com/u/rc_v3.rar and http://nishi.dreamhosters.com/u/o01_v0.rar

April 3, 2011 at 3:24 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.