Skip to content

Instantly share code, notes, and snippets.

@bkuhns
Last active December 11, 2015 14:09
Show Gist options
  • Save bkuhns/4612326 to your computer and use it in GitHub Desktop.
Save bkuhns/4612326 to your computer and use it in GitHub Desktop.
Is std::async().... async?
#include "stdafx.h"
#include <iostream>
#include <thread>
#include <future>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main()
{
cout << "Main thread: " << std::this_thread::get_id() << endl;
auto f = async([] {
unsigned int big = std::numeric_limits<unsigned int>::max();
while(big != 0) {
big--;
if(big == 0) {
cout << "Worker thread: " << std::this_thread::get_id() << endl;
}
this_thread::sleep_for(milliseconds(10));
}
});
f.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment