Skip to content

Instantly share code, notes, and snippets.

@divanvisagie
Created November 3, 2013 15:58
Show Gist options
  • Select an option

  • Save divanvisagie/7291744 to your computer and use it in GitHub Desktop.

Select an option

Save divanvisagie/7291744 to your computer and use it in GitHub Desktop.
Async and function implementation in C++
#include <iostream>
#include <cstdlib>
#include <unistd.h> //for sleep
#include <future>
#include <map>
using namespace std;
map<string,function<void()>> my_functions = {
{ "test", [](){
cout << "test function" << endl;
}},
{ "long", [](){
cout << "long: before loop" << endl;
for (int i = 0; i < 1e9; i++){}
cout << "long: after loop" << endl;
}},
};
int main(int argc, const char * argv[]){
future<void> a(async(my_functions["long"]));
my_functions["test"]();
a.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment