想不通为什么这个看似递归,readKey的调用不会导致越来越多的调用堆栈:C++异步拉姆达“递归”呼叫
#include <future>
#include <iostream>
void readKey()
{
std::async(std::launch::async, [](){
if (getchar() != 113) // 'q' to quit
readKey();
});
}
int main(int, char**)
{
readKey();
return 0;
}
谢谢堡垒解释!
:-)
你如何确定调用堆栈大小? –
没有线程曾多次调用'readKey();'。每次调用'std :: async'都会创建一个新线程,并创建一个新的堆栈。 –
@FrançoisAndrieux析构函数中'async'块返回的'std :: future'直到线程结束。 – NathanOliver