Skip to content

Instantly share code, notes, and snippets.

@mikeplavsky
Last active August 29, 2020 22:09
Show Gist options
  • Save mikeplavsky/4e4bee75ba13cc0fabd8141bbc6831cb to your computer and use it in GitHub Desktop.
Save mikeplavsky/4e4bee75ba13cc0fabd8141bbc6831cb to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <memory>
#include <forward_list>
#include <typeinfo>
#include <thread>
#include <mutex>
using namespace std;
mutex m;
void test(int i) {
lock_guard<mutex> g(m);
cout << " "
<< i
<< " "
<< this_thread::get_id()
<< std::endl;
}
int main()
{
array<thread,9> arr = {
thread{test,1},
thread{test,2},
thread{test,3},
thread{test,4},
thread{test,5},
thread{test,6},
thread{test,7},
thread{test,8},
thread{test,9}};
for (auto &t: arr) {
t.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment