Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fibers in C#: are they faster than iterators, and have people used them?

So I was chatting with a colleague about fibers and turned up this paper from 2003 that describes a implementation of coroutines in C# using the Fiber API.

The implementation of Yield in this paper was for .NET 1.1, so it predates the yield return syntax that appeared in .NET 2.0.

It definitely looks, at first glance, that the implementation here is potentially faster and could scale across multiple CPUs rather well.

Has anyone used it?

like image 339
Jeremy McGee Avatar asked Dec 10 '09 14:12

Jeremy McGee


1 Answers

I haven't used it, but I have an interest in the subject. Here's one nice implementation of coroutines in C# with a round-robin scheduler: http://www.bluebytesoftware.com/blog/PermaLink.aspx?guid=71235c5a-3753-4bab-bdb0-334ab439afaf

By the way, quoting wikipedia, "fibers describe essentially the same concept as coroutines". As far as I know, the closest thing to a coroutine (or a fiber) in C# are iterators. Actually, they are remarkably close to coroutines. Lippert posted several catches about iterators. Hopefully, none of them represent an serious problem for the purposes you need.

like image 146
jpbochi Avatar answered Nov 16 '22 02:11

jpbochi