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