Going Beyond the Standard: Continuations in Mono

| by Jonathan Allen Follow 465 Followers on Mar 09, 2011. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

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.

Rate this Article

Adoption Stage

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


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you