Вопрос

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)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top