BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Going Beyond the Standard: Continuations in Mono

by Jonathan Allen on Mar 09, 2011 |

While Mono usually strives to follow the C# and Common Language Infrastructure specifications, it does occasionally go beyond them. While some features such as SIMD support are backwards-compatible with .NET, runtime supported continuations are exclusive to Mono.

A continuation is like a thread frozen in time, a snap-shot if you will. It includes stack frames and local variables, but unlike a true thread it is not executable. A simple form of continuation can be seen in C#’s yield operator. But yield is just a compiler trick that creates a state machine; it isn’t a general purpose continuation. For that you need almost need support from the runtime.

The result of Tomi Valkeinen's research into runtime support is the Mono.Tasklet API. This allows for general purpose continuations that actually capture the stack. The stack can be restored as often as necessary. It should be noted that this form of continuation can capture references but not the heap allocated objects those references point to. On top of this he built his microthreading library. This consists of lightweight threads that use continuations and cooperative multitasking to share a single physical thread.

Earlier we said “almost” because there is another way to build a general purpose continuation. Jim Purbrick of LindenLabs built a continuation system that uses CIL rewriting instead of runtime suppport. Compared to Valkeinen's continuations, this is a rather heavy weight way to build continuations. But it does have the ability to serialize not only the stack but also objects on the heap. This allows the continuation to be restored on another server, which is very important to Second Life’s scalable architecture. Long term LindenLabs would like to combine the two techniques, using Mono Tasklets for fast continuations and their technique when continuations need to be serialized.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT