开发者

C++ std::async vs async/await in C#

开发者 https://www.devze.com 2023-02-21 17:36 出处:网络
I\'m wondering if the new开发者_运维百科 c++ feature std::async is quite comparable to the two C# keywords async/await or not and if not why?Not really, assuming I\'m reading this std::async documenta

I'm wondering if the new开发者_运维百科 c++ feature std::async is quite comparable to the two C# keywords async/await or not and if not why?


Not really, assuming I'm reading this std::async documentation correctly.

C# 5's async/await feature involves a complex compiler transformation of the asynchronous method so that you can write code which looks pretty much synchronous, but has points of asynchrony. The compiler builds a state machine for you, creates appropriate callbacks etc.

EDIT: While I previously believed that std::async simply forced you to pass in a callback explicitly, it looks like it's even more primitive than that. Either way, I believe it's mostly/completely a library feature whereas C# 5's asynchronous methods are mostly a language feature with library support.

EDIT: As noted further in comments, it looks like it's on its way for VC++...


CPPASYNC (provided in another answer) looks like what you are looking for. The "Async" part is easy and the performance looks good (likely better than the C# implementation). It's ugly b/c you need special "Await" wrappers around async callback calls. Some Boost networking is provided, and they're easy to make, but you can't just "Await" anything: Async any method/function,

Within an Async function, await either:
- An Async function
- An await wrapper (simple to make) around an asynchronous function (that takes a callback)

0

精彩评论

暂无评论...
验证码 换一张
取 消