Created
November 3, 2013 15:58
-
-
Save divanvisagie/7291744 to your computer and use it in GitHub Desktop.
Async and function implementation in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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