Coroutines In Dot Net

.NET 2.0 (a.k.a. Whidbey) has several interesting features for those looking for coroutines.

The C# compiler supports both blocks/closures and iterators. See BlocksInCsharp for more info.

Also, the CLR supports a new set of COM-based hosting interfaces that supersede those described in the article below. Those new hosting interfaces are used by SQL Server 2005's fiber-based scheduler.

The use of the earlier versions of these interfaces (ICorRuntimeHost et al) are not supported in a fiber-based environment.

-- DonBox


Implementing Coroutines for .NET by Wrapping the Unmanaged Fiber API

"Coroutines are a powerful feature of many programming languages, including CLU, Scheme, Python, Ruby, and ICON. Coroutines can save processor overhead and reduce redundancy because they allow you to stop execution of a procedure midstream, return a value, and resume exactly where the procedure left off."

-- http://msdn.microsoft.com/msdnmag/issues/03/09/CoroutinesinNET/


What is the relationship between "blocks" and "coroutines"? Is there some programming language where the two terms are synonymous?

If there is relationship, perhaps this page should be renamed "CoroutinesInDotNet".

This page should be renamed, because that article has nothing to do with blocks; a block would be an anonymous delegate, which will be in the next version of C sharp. It's about using fibers to simulate yield to give you coroutines, which has nothing at all to do with blocks/anonymous functions.

It depends on your definition of "coroutine". Blocks are commonly used with internal iterators. Control passes back and forth between the iterator and the block until the iterating is done. This is sometimes considered to be an example of coroutines. In this sense, SmalltalkLanguage would be one where "block" and "coroutine" are (somewhat) synonymous. -- JasonArhart

It's an example of a coroutine, but blocks are used for far more than just iteration. Blocks are anonymous functions, often with lexical scope, and are a completely different concept than coroutines.


CategoryClosure CategoryDotNet


EditText of this page (last edited April 2, 2006) or FindPage with title or text search