【发布时间】:2017-02-09 05:08:07
【问题描述】:
C++11
int main(int argc, char** argv) {
std::async(std::launch::async, [](){
while(true) cout << "async thread" <<endl;
});
while(true) cout << "main thread" << endl;
return 0;
}
我预计输出应该与 async thread 和 main thread 交错,因为应该有 2 个不同的线程。
但事实并非如此。
它输出:
async thread
async thread
async thread
async thread
...
我猜只有一个线程。有人能告诉我为什么它没有为std::async 生成一个新线程吗?谢谢。
【问题讨论】:
标签: c++ multithreading asynchronous stdasync