Skip to content

Instantly share code, notes, and snippets.

@mikeplavsky
Last active September 14, 2020 14:28
Show Gist options
  • Save mikeplavsky/c2f4ee2be6eafd09649645a919d391a6 to your computer and use it in GitHub Desktop.
Save mikeplavsky/c2f4ee2be6eafd09649645a919d391a6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <mutex>
#include <future>
using namespace std;
int main()
{
mutex m;
auto t = [](int i) {
lock_guard<mutex> g(m);
cout << " "
<< i
<< " "
<< this_thread::get_id()
<< std::endl;
return i;
};
array v{
async(launch::async, t, 1),
async(launch::async, t, 2),
async(launch::async, t, 3),
async(launch::async, t, 4),
async(launch::async, t, 5)};
for (auto &x:v) {
cout << x.get()
<< std::endl;
}
}
@mikeplavsky
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment