Delimited continuations for C/C++

Hello LtU,

I have created a monster. I have implemented a variant of shift/reset control operators, shift0/reset0, for C/C++. The core of the implementation is written in x86 assembly and works by heap-allocating new stacks and switching between them. There are some caveats, but otherwise everything seems to be working nice.

I've shared the implementation on github. Could you take a look at it and share some comments?

(And yes, I know this is crazy.)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I am very interested.

Thanks for posting this! Sounds like exactly what I want. I will have a look and tell you what I think.

Are the thunks garbage-collected?

No garbage collection

The user is responsible for freeing the captured continuations. You could probably use some external garbage collector, if you need it.

Stack manipulation in semi-portable C

You can allocate stacks and switch between them using setjmp, longjmp, and either alloca() or variable-size local arrays to adjust the stack pointer into a new section of memory. See some example code i posted to my blog a while back. To allocate the stack on the heap, calculate a new top-of-stack using malloc() instead of arithmetic on a stack location.

libconcurrency is along the

libconcurrency is along the same lines. You can find fibers (for Windows), stack-copying (which is the most portable), and stack-switching backends in 100% C. Your approach looks like an interesting variant though, so I'll have to digest it further.