F#的异步状态机与C#的异步或Go语言的go命令相同吗?

huangapple go评论92阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2014年4月20日 22:12:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/23183414.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定