Skip to content

Instantly share code, notes, and snippets.

@usagi
Created January 20, 2014 17:21
Show Gist options
  • Select an option

  • Save usagi/8524485 to your computer and use it in GitHub Desktop.

Select an option

Save usagi/8524485 to your computer and use it in GitHub Desktop.
#include <thread>
#include <chrono>
#include <string>
#include <iostream>
int main()
{
std::cerr << "<press enter to exit>\n";
bool to_continue = true;
auto main_loop_thread = std::thread([&]()
{
size_t n = 0;
while(to_continue)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cerr << n++ << ' ';
}
});
std::string buffer;
std::getline(std::cin, buffer);
to_continue = false;
main_loop_thread.join();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment