p*****2 发帖数: 21240 | 1 这东西就是Scala里的future,node.js也已经有了。并不是C#独有的。 |
m*******l 发帖数: 12782 | 2 and C++
【在 p*****2 的大作中提到】 : 这东西就是Scala里的future,node.js也已经有了。并不是C#独有的。
|
N********n 发帖数: 8363 | 3
Scala也在加async/await, 基本上裸抄C#。NODE用啥不知道,但只要是还
在写CALLBACK METHOD就不是真正的async/await。
【在 p*****2 的大作中提到】 : 这东西就是Scala里的future,node.js也已经有了。并不是C#独有的。
|
p*****2 发帖数: 21240 | 4
await里边的线程之间通信C#主要是靠什么机制呀?
【在 N********n 的大作中提到】 : : Scala也在加async/await, 基本上裸抄C#。NODE用啥不知道,但只要是还 : 在写CALLBACK METHOD就不是真正的async/await。
|
p*****2 发帖数: 21240 | 5 我怎么感觉Go就可以秒杀C#呀?难道我理解有误? |
x****u 发帖数: 44466 | 6 C#靠的是整个framework,Java也一样,语言本身是次要的。
【在 p*****2 的大作中提到】 : 我怎么感觉Go就可以秒杀C#呀?难道我理解有误?
|
p*****2 发帖数: 21240 | 7
我是说异步。
【在 x****u 的大作中提到】 : C#靠的是整个framework,Java也一样,语言本身是次要的。
|
g****r 发帖数: 1589 | 8 都异步了还搞啥线程通讯啊
【在 p*****2 的大作中提到】 : : 我是说异步。
|
x****u 发帖数: 44466 | 9 C#的没研究过,C++/CX靠的是lambda语法加上线程池,没什么新东西。
【在 g****r 的大作中提到】 : 都异步了还搞啥线程通讯啊
|
p*****2 发帖数: 21240 | 10
靠。异步就不线程通信了?你把Go,Erlang,Scala一起骂了。
【在 g****r 的大作中提到】 : 都异步了还搞啥线程通讯啊
|
|
|
g****r 发帖数: 1589 | 11 异步本来就不是啥新玩意啊,c#的精髓是你只需要按写同步程序的方法就能写个异步的
程序,编译器和framework帮你把你的程序分解成不同的piece在相应io完成时执行。所
以实际上你就是写了一个顺序执行的程序,要是用node,你得自己写一堆callback,算
不上多麻烦,不过就是developer friendly的程度罢了
【在 x****u 的大作中提到】 : C#的没研究过,C++/CX靠的是lambda语法加上线程池,没什么新东西。
|
p*****2 发帖数: 21240 | 12
关键是这东西不是C#独有呀。
【在 g****r 的大作中提到】 : 异步本来就不是啥新玩意啊,c#的精髓是你只需要按写同步程序的方法就能写个异步的 : 程序,编译器和framework帮你把你的程序分解成不同的piece在相应io完成时执行。所 : 以实际上你就是写了一个顺序执行的程序,要是用node,你得自己写一堆callback,算 : 不上多麻烦,不过就是developer friendly的程度罢了
|
n*w 发帖数: 3393 | 13 f#也有呀。
【在 p*****2 的大作中提到】 : : 关键是这东西不是C#独有呀。
|
p*****2 发帖数: 21240 | 14
F#里线程是如何通信的呀?
【在 n*w 的大作中提到】 : f#也有呀。
|
N********n 发帖数: 8363 | 15
As someone pointed out b4, the key is AVOIDING CALLBACK b/c callback
is merely a different form of GOTO: When asynchronous operations finish,
control flow GOES TO your callback methods.
When you have to write many asynchronous operations you end up with many
"GOTO" callback methods in your code that ruin its structure, which is
bad so you wanna avoid them, and that's where async/await helps.
Threading is not relevant here.
【在 p*****2 的大作中提到】 : : F#里线程是如何通信的呀?
|
p*****2 发帖数: 21240 | 16
我不是说了吗?Scala的Future就可以干这事。
【在 N********n 的大作中提到】 : : As someone pointed out b4, the key is AVOIDING CALLBACK b/c callback : is merely a different form of GOTO: When asynchronous operations finish, : control flow GOES TO your callback methods. : When you have to write many asynchronous operations you end up with many : "GOTO" callback methods in your code that ruin its structure, which is : bad so you wanna avoid them, and that's where async/await helps. : Threading is not relevant here.
|
N********n 发帖数: 8363 | 17
It's naked copy of C# async/await, and I don't know node.js has a
counterpart.
【在 p*****2 的大作中提到】 : : 我不是说了吗?Scala的Future就可以干这事。
|
p*****2 发帖数: 21240 | 18
这个就搞了吧?Scala的future存在很久了吧?
【在 N********n 的大作中提到】 : : It's naked copy of C# async/await, and I don't know node.js has a : counterpart.
|
N********n 发帖数: 8363 | 19
Scala's original "future" was probably from Java. It's after its
designers saw the power of async/await that they decided to copy
the feature to Scala.
【在 p*****2 的大作中提到】 : : 这个就搞了吧?Scala的future存在很久了吧?
|
g****r 发帖数: 1589 | 20 这种东西想独有挺难的,无非实现方式的一些差别罢了
【在 p*****2 的大作中提到】 : : 这个就搞了吧?Scala的future存在很久了吧?
|
|
|
p*****2 发帖数: 21240 | 21
这么说有什么依据吗?
【在 N********n 的大作中提到】 : : Scala's original "future" was probably from Java. It's after its : designers saw the power of async/await that they decided to copy : the feature to Scala.
|
p*****2 发帖数: 21240 | 22
嗯。上次我看论坛上谈起来以为是什么很特别的东西呢。结果一看就跟Scala的Future
差不多。还没有Go功能强大。
【在 g****r 的大作中提到】 : 这种东西想独有挺难的,无非实现方式的一些差别罢了
|
g****r 发帖数: 1589 | 23 看了下scala的future,这个还真是老一套的东西,基本相当于.net 3.5里面
asyncresult类似的一个东西,还真比async/await差一些
go看着挺颠覆的,之前看了点,没感觉咋样,有啥async编程的例子吗,我研究研究?
Future
【在 p*****2 的大作中提到】 : : 嗯。上次我看论坛上谈起来以为是什么很特别的东西呢。结果一看就跟Scala的Future : 差不多。还没有Go功能强大。
|
g****r 发帖数: 1589 | 24 异步和多线程编程不是一回事,虽然都用到了线程
我觉得传统认为的多线程编程更多的是为了utilize cpu,各种各样的线程同步都不可
避免的占用了更多的系统资源
而异步编程的范围要广得多,写backend的时候,为了提高throughput,系统里的线程
和线程切换那是越少越好,如果单核的机器的话,那最好就是一个线程运行到底,这时
候为了处理多个请求那就只能异步编程了
个人浅见,说错了别骂我,哈哈
【在 p*****2 的大作中提到】 : : 嗯。上次我看论坛上谈起来以为是什么很特别的东西呢。结果一看就跟Scala的Future : 差不多。还没有Go功能强大。
|
x****u 发帖数: 44466 | 25 用了lambda语法也差不多,异步的主要问题是需要平台级的framework支持,这恰恰是C
++不愿意做的东西。用了C++/CX就得上Win8的船。
【在 g****r 的大作中提到】 : 异步本来就不是啥新玩意啊,c#的精髓是你只需要按写同步程序的方法就能写个异步的 : 程序,编译器和framework帮你把你的程序分解成不同的piece在相应io完成时执行。所 : 以实际上你就是写了一个顺序执行的程序,要是用node,你得自己写一堆callback,算 : 不上多麻烦,不过就是developer friendly的程度罢了
|
p*****2 发帖数: 21240 | 26
你觉得主要是差在哪里呢?
go提供了线程之间的通信方式,这个我看C#没提供。
【在 g****r 的大作中提到】 : 看了下scala的future,这个还真是老一套的东西,基本相当于.net 3.5里面 : asyncresult类似的一个东西,还真比async/await差一些 : go看着挺颠覆的,之前看了点,没感觉咋样,有啥async编程的例子吗,我研究研究? : : Future
|
p*****2 发帖数: 21240 | 27
你说的没什么错的。但是不代表线程之间在异步的情况不需要通信呀。
【在 g****r 的大作中提到】 : 异步和多线程编程不是一回事,虽然都用到了线程 : 我觉得传统认为的多线程编程更多的是为了utilize cpu,各种各样的线程同步都不可 : 避免的占用了更多的系统资源 : 而异步编程的范围要广得多,写backend的时候,为了提高throughput,系统里的线程 : 和线程切换那是越少越好,如果单核的机器的话,那最好就是一个线程运行到底,这时 : 候为了处理多个请求那就只能异步编程了 : 个人浅见,说错了别骂我,哈哈
|
k**********g 发帖数: 989 | 28
是C
Win7 也可以「仿」async/await。 沒有 syntactic sugar。
用 C++11 和 MS 自家的 Parallel Patterns Library
但是软件要在 Win7 用VS2012开发,编译後可以拿到XP/Vista/Win7/Win8运行
But according to Jon Skeet, whatever is available on C++ is still quite
primitive when compared to what's on other languages. C++ still has a long
way to go.
http://stackoverflow.com/questions/5498701/c-stdasync-vs-async-
【在 x****u 的大作中提到】 : 用了lambda语法也差不多,异步的主要问题是需要平台级的framework支持,这恰恰是C : ++不愿意做的东西。用了C++/CX就得上Win8的船。
|
k**********g 发帖数: 989 | 29
In the past, multicore programming focuses on fully utilizing CPU. This can
be seen in the High-Performance Computing (HPC) benchmark rankings.
This approach neglects an issue that is ubiquitous: Most "processes" (
including computations, communications, and I/O) do not generate (yield) a
block of "result" of size N at once. Instead, almost all real-world
processes yield results incrementally.
To visualize, one can imagine this at a microscopic timing level:
After spending 500 microseconds of initial processing,
The first data element (e.g. a database row) arrives at 505 usecs.
The second element arrives at 510 usecs.
The third element arrives at 515 usecs.
The fourth arrives at 520 usecs.
...
The N-th arrives at 500 + (5 * N) usecs.
This nature, which I call "incrementalism", is synergistic with the concept
that is "concurrency".
In the past, a great deal of "multicore" programs were written to kill
incrementalism, thinking that it is a nuisance.
Nowadays, those old style programs were in turn killed in favor of new
programs written to take advantage of both incrementalism and concurrency.
【在 g****r 的大作中提到】 : 异步和多线程编程不是一回事,虽然都用到了线程 : 我觉得传统认为的多线程编程更多的是为了utilize cpu,各种各样的线程同步都不可 : 避免的占用了更多的系统资源 : 而异步编程的范围要广得多,写backend的时候,为了提高throughput,系统里的线程 : 和线程切换那是越少越好,如果单核的机器的话,那最好就是一个线程运行到底,这时 : 候为了处理多个请求那就只能异步编程了 : 个人浅见,说错了别骂我,哈哈
|
g****r 发帖数: 1589 | 30 比如把google down下来并打印出来
你用future写就是
var f=future{
httpGet("www.google.com");
oncomplete{
case(success):(r)=>println(r);
}
}
你用c#写就是
var r=await httpGet("www.google.com");
println(r);
看着就是一个同步程序,但其实编译器帮你把他异步执行了,不用explicit的callback
,可读性好点罢了
【在 p*****2 的大作中提到】 : : 你说的没什么错的。但是不代表线程之间在异步的情况不需要通信呀。
|
|
|
p*****2 发帖数: 21240 | 31
这个同意。语法确实没有C#简洁,不过语法这东西改进一下也不难。
【在 g****r 的大作中提到】 : 比如把google down下来并打印出来 : 你用future写就是 : var f=future{ : httpGet("www.google.com"); : oncomplete{ : case(success):(r)=>println(r); : } : } : 你用c#写就是 : var r=await httpGet("www.google.com");
|
p*****2 发帖数: 21240 | 32
对了,你知道async/await是怎么设计出来的吗?参考了其他异步方案吗?
【在 g****r 的大作中提到】 : 比如把google down下来并打印出来 : 你用future写就是 : var f=future{ : httpGet("www.google.com"); : oncomplete{ : case(success):(r)=>println(r); : } : } : 你用c#写就是 : var r=await httpGet("www.google.com");
|
N********n 发帖数: 8363 | 33
C# introduced async/await in 2012. Scala designers were "inspired by C#"
and brought them to Scala in 2013.
Listen to their explanation here:
http://parleys.com/play/51c0b264e4b0d38b54f461f2/chapter2/about
【在 p*****2 的大作中提到】 : : 对了,你知道async/await是怎么设计出来的吗?参考了其他异步方案吗?
|
N********n 发帖数: 8363 | 34 Imagine you wanna run 3 async operations in a method like below:
void foo () {
// run async_op1, async_op2 & async_op3
}
W/ callbacks you'd have to break it down into several callbacks:
void foo () { run_async (op1, op1_callback);}
void op1_callback () {run_async (op2, op2_callback);}
void op2_callback () {run_async (op3, op2_callback);}
void op3_callback () {//finish the rest;}
Now you are forced to break the logic down into spaghetti callback
methods. If one async_op requires output from another, you'd have
to come up w/ an awkward way to wrap parameters between callback
methods. The code looks ugly and is hard to maintain.
That's why async/await is IMO a must-have for modern languages and
apparently the Scala folks realized it. |
p*****2 发帖数: 21240 | 35
这个东西不错,今天好好看看。多谢了。
【在 N********n 的大作中提到】 : Imagine you wanna run 3 async operations in a method like below: : void foo () { : // run async_op1, async_op2 & async_op3 : } : W/ callbacks you'd have to break it down into several callbacks: : void foo () { run_async (op1, op1_callback);} : void op1_callback () {run_async (op2, op2_callback);} : void op2_callback () {run_async (op3, op2_callback);} : void op3_callback () {//finish the rest;} : Now you are forced to break the logic down into spaghetti callback
|
p*****2 发帖数: 21240 | 36
这个没错。不过这东西Go里面也有。Node很快也会加上去了。
我感觉Go实现的可能比C#更彻底。C#你还需要意识到什么时候是同步,什么时候是异步
,Go给我的感觉应该是你基本不用考虑异步了,系统都给你干了。
【在 N********n 的大作中提到】 : Imagine you wanna run 3 async operations in a method like below: : void foo () { : // run async_op1, async_op2 & async_op3 : } : W/ callbacks you'd have to break it down into several callbacks: : void foo () { run_async (op1, op1_callback);} : void op1_callback () {run_async (op2, op2_callback);} : void op2_callback () {run_async (op3, op2_callback);} : void op3_callback () {//finish the rest;} : Now you are forced to break the logic down into spaghetti callback
|
p*****2 发帖数: 21240 | 37
这个是讲Scala Async的吧?不是说Scala Future的。
我想知道Scala的Future也是学C#的吗?这东西貌似很早之前就有了吧?
【在 N********n 的大作中提到】 : Imagine you wanna run 3 async operations in a method like below: : void foo () { : // run async_op1, async_op2 & async_op3 : } : W/ callbacks you'd have to break it down into several callbacks: : void foo () { run_async (op1, op1_callback);} : void op1_callback () {run_async (op2, op2_callback);} : void op2_callback () {run_async (op3, op2_callback);} : void op3_callback () {//finish the rest;} : Now you are forced to break the logic down into spaghetti callback
|
p*****2 发帖数: 21240 | 38
Scala 2.10 has integrated the Future concept from Akka, still available by
means of Akka for Scala < 2.10. You are right, Task is analogous to
Future[T] from Scala.
I also don't like the async/await feature from C# or the experimental
delimitated continuations support. Async programming by means of Futures
works great without it and looking at my code, I don't see many places where
I could actually use the async/await syntactic sugar. That's because
modelling computations in terms of Future objects is like working with Lego
blocks ... you want control the context in which they are executed, what
should run in parallel, what should run as a continuation, how to faillover
or handle errors in case of failure and so on and so forth.
Also working with Future[T] is much better than working with Task. Try it
out and you'll see.
【在 p*****2 的大作中提到】 : : 这个是讲Scala Async的吧?不是说Scala Future的。 : 我想知道Scala的Future也是学C#的吗?这东西貌似很早之前就有了吧?
|
r*g 发帖数: 3159 | 39 c#是从f#借来的异步编程。
【在 N********n 的大作中提到】 : Imagine you wanna run 3 async operations in a method like below: : void foo () { : // run async_op1, async_op2 & async_op3 : } : W/ callbacks you'd have to break it down into several callbacks: : void foo () { run_async (op1, op1_callback);} : void op1_callback () {run_async (op2, op2_callback);} : void op2_callback () {run_async (op3, op2_callback);} : void op3_callback () {//finish the rest;} : Now you are forced to break the logic down into spaghetti callback
|
p*****2 发帖数: 21240 | 40 有看了看。感觉F#,C#的这个设计还是挺牛的。感觉也就是Scala里有这个东西,别的
语言还真没有。node目前的正式版本还没有,试用版有。 |
|
|
c******o 发帖数: 1277 | 41 不熟c#
Scala 的future重点是能用flatMap/map composite.
多个future 可以用任意逻辑对其中的结果任意组合 (同时每一个都是独立,相对其他
async)(除非参数上有相对的先后,那也是自动会等待), 我一个callback都不用写,
只用在最后为组合的总和写一个(要是在一些framework里,最后一个 callback 都被
代劳了)。
【在 g****r 的大作中提到】 : 看了下scala的future,这个还真是老一套的东西,基本相当于.net 3.5里面 : asyncresult类似的一个东西,还真比async/await差一些 : go看着挺颠覆的,之前看了点,没感觉咋样,有啥async编程的例子吗,我研究研究? : : Future
|
c****e 发帖数: 1453 | 42 本质上就是有了yield return,compiler把程序flow的状态机给展开了。这个对于
exception的处理也支持的很好,写起来基本是无脑的。C# 2.0的时候就有第三方的
library做这个了。Python也有类似的东西。
【在 p*****2 的大作中提到】 : 有看了看。感觉F#,C#的这个设计还是挺牛的。感觉也就是Scala里有这个东西,别的 : 语言还真没有。node目前的正式版本还没有,试用版有。
|
k**********g 发帖数: 989 | 43
还有一点就是把 coroutine/yield reentry 的状态(类似於enum)封装成一个
windows message,发到 windows 的 message dispatch loop。
【在 c****e 的大作中提到】 : 本质上就是有了yield return,compiler把程序flow的状态机给展开了。这个对于 : exception的处理也支持的很好,写起来基本是无脑的。C# 2.0的时候就有第三方的 : library做这个了。Python也有类似的东西。
|
p*****2 发帖数: 21240 | 44 有看了一下,感觉还是C#比Scala future强大。 |