Last active
September 14, 2020 14:28
-
-
Save mikeplavsky/c2f4ee2be6eafd09649645a919d391a6 to your computer and use it in GitHub Desktop.
This file contains 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 <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; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://coliru.stacked-crooked.com/a/2155f4a88d59869e