英文:
Are F#'s async state machines the same as C#'s async or go-lang's go command?
问题
这里我们看到了Don Syme关于F#中异步状态机的论文。我正在努力理解它。
我的问题是,这个与C#中的async命令(以及go-lang中的go命令)是否做相同的事情?
英文:
Here we see a paper by Don Syme on Async state machines in F#. I'm trying to get my head around it.
My question is - does this do the same thing as the async command in C#? (and the go command in go-lang)
答案1
得分: 0
这不完全相同,但是C#也使用状态机来在编译时构建方法的异步版本。
请参考Mads Torgersen的一篇很棒的文章http://msdn.microsoft.com/en-us/magazine/hh456403.aspx,了解有关C#异步标记在编译器中如何重写方法的内容。
在Go语言中,goroutine在概念上更类似于.NET TPL(任务并行库)而不是异步标记。如果goroutine变得阻塞,它会在线程上被另一个goroutine替换,因此你实际上是在使用线程池构造。Go语言在底层为你处理非阻塞I/O。
英文:
It's not exactly the same, no, but C# also uses state machines to build the async versions of methods on compilation.
See http://msdn.microsoft.com/en-us/magazine/hh456403.aspx for a great article by Mads Torgersen about how methods are rewritten in the compiler for C#'s async token.
In golang, goroutines are much more similar to the .Net TPL than the async token, conceptually. A goroutine is swapped out for another on a thread if it becomes blocking, so you're working with more of a thread pool construct. Go handles the non-blocking I/O for you under the hood.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论