草庐IT

TestAsync

全部标签

c++ - std::async 不能异步工作

我有以下非常简单的代码:voidTestSleep(){std::cout因为我使用std::launch::async我希望TestSleep()将异步运行并且我将得到以下输出:TestAsyncTestAsyncok!!!TestSleepTestSleepOk但实际上我有同步运行的输出:TestAsyncTestSleepTestSleepOkTestAsyncok!!!您能解释一下为什么以及如何使TestSleep真正异步调用吗。 最佳答案 来自thisstd::asyncreferencenotessectionIfthe