1namespace {
2 std::vector<std::thread> workers;
3
4 int total = 4;
5 int arr[4] = {0};
6
7 void each_thread_does(int i) {
8 arr[i] += 2;
9 }
10}
11
12int main(int argc, char *argv[]) {
13 for (int i = 0; i < 8; ++i) { // for 8 iterations,
14 for (int j = 0; j < 4; ++j) {
15 workers.push_back(std::thread(each_thread_does, j));
16 }
17 for (std::thread &t: workers) {
18 if (t.joinable()) {
19 t.join();
20 }
21 }
22 arr[4] = std::min_element(arr, arr+4);
23 }
24 return 0;
25}
26