Search
 
SCRIPT & CODE EXAMPLE
 

CPP

vector of threads thread pool c++

namespace {
  std::vector<std::thread> workers;

  int total = 4;
  int arr[4] = {0};

  void each_thread_does(int i) {
    arr[i] += 2;
  }
}

int main(int argc, char *argv[]) {
  for (int i = 0; i < 8; ++i) { // for 8 iterations,
    for (int j = 0; j < 4; ++j) {
      workers.push_back(std::thread(each_thread_does, j));
    }
    for (std::thread &t: workers) {
      if (t.joinable()) {
        t.join();
      }
    }
    arr[4] = std::min_element(arr, arr+4);
  }
  return 0;
}
Comment

vector of threads thread pool c++

namespace {
  std::vector<std::thread> workers;

  int total = 4;
  int arr[4] = {0};

  void each_thread_does(int i) {
    arr[i] += 2;
  }
}

int main(int argc, char *argv[]) {
  for (int i = 0; i < 8; ++i) { // for 8 iterations,
    for (int j = 0; j < 4; ++j) {
      workers.push_back(std::thread(each_thread_does, j));
    }
    for (std::thread &t: workers) {
      if (t.joinable()) {
        t.join();
      }
    }
    arr[4] = std::min_element(arr, arr+4);
  }
  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ recursion 
Cpp :: exception handling class c++ 
Cpp :: resize vector c++ 
Cpp :: c++ insert variable into string 
Cpp :: how to grab numbers from string in cpp 
Cpp :: find pair with given sum in the array 
Cpp :: changing values of mat in opencv c++ 
Cpp :: find positive number factorial in C++ 
Cpp :: convert wchar_t to to multibyte 
Cpp :: cpp read from file 
Cpp :: print Colored text in C++ 
Cpp :: resharper fold if statement 
Cpp :: cmake g++ address sanitizer 
Cpp :: c++ thread wait fro 1 sec 
Cpp :: balanced parentheses 
Cpp :: google test assert throw 
Cpp :: prime number program c++ 
Cpp :: c++ std map initializer list 
Cpp :: backtrack 
Cpp :: size of unordered_set 
Cpp :: delete c++ 
Cpp :: c++ string concatenation 
Cpp :: Valid Parentheses leetcode in c++ 
Cpp :: declare class c++ 
Cpp :: c++ char 
Cpp :: ue4 c++ switch enum 
Cpp :: java to puthon converter 
Cpp :: Write a C++ program to Computing Mean and Median Using Arrays 
Cpp :: c++ solver online free 
Cpp :: c++ camera capture 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =