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

前端 未结 3 1783
滥情空心
滥情空心 2020-12-28 10:32

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 imple

3条回答
  •  醉梦人生
    2020-12-28 11:00

    I have used yield-based "coroutines," and I have to say that they are a pain in the butt. The problem is, of course, that everywhere you want to use them, you're forced to use the yield syntax. Not only that, but unless you chain yields (parent yields child's yield), you can only ever nest your coroutines one level deep. This completely destroys one of the key benefits of coroutines (full stack save/restore).

    I implemented a fiber-based coroutine system in C# and it worked wonderfully UNTIL I hit an exception. Unfortunately the .Net runtime stores a bunch of internal exception stuff in OS threads, which means that emulating multiple threads using OS fibers (and p/invoke) just won't work unless you'll never, ever, ever have an exception.

提交回复
热议问题