1
C++ 11C++的std ::异步不会产生一个新的线程
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
?谢谢。
http://en.cppreference.com/w/cpp/thread/async - 阅读注释。 – chris