Questions tagged «packaged-task»

3
packaged_task和async有什么区别
在使用C ++ 11的线程模型时,我注意到 std::packaged_task<int(int,int)> task([](int a, int b) { return a + b; }); auto f = task.get_future(); task(2,3); std::cout << f.get() << '\n'; 和 auto f = std::async(std::launch::async, [](int a, int b) { return a + b; }, 2, 3); std::cout << f.get() << '\n'; 似乎做的完全一样。我知道,如果std::async与一起跑步,可能会有很大的不同std::launch::deferred,但是在这种情况下,有没有区别? 这两种方法之间有什么区别,更重要的是,我应该在哪种用例中使用一种而不是另一种?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.