Can't figure out why this, seemingly recursive, invocation of readKey doesn't result in a growing call stack:
#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;
}
Thank you fort explaining!
:-)
readKey();more than once. Each call tostd::asynccreates a new thread with a fresh stack.std::futurereturned byasyncblocks in the destructor until the thread finishes.joins the thread? isn't it UB to not join it?join()).