async in C++11
-
hi, was macht folgender code genau? was macht dieses then genau?
#include <thread> #include <future> template<typename Fut, typename Work> auto then(Fut f, Work w)->std::future<decltype(w(f.get()))> { return std::async([=] { w(f.get()); }); } int main() { std::future<int> result = std::async([]{ return 12;}); auto f = then(std::move(result), [](int r) { std::cout << "[after] thread id = " << std::this_thread::get_id()<< std::endl; std::cout << "r = " << r << std::endl; return r*r; }); std::cout << "Final result f = " << f.get() << std::endl; return 0;
-
Verkettung asychroner Operationen: http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Herb-Sutter-Concurrency-and-Parallelism