c++ - how to declare a vector of thread -
i'm new in c++ programing , need use thread library vector library...
first follow tutorial
but compiler (visual studio 2013) show me errors , don't know how correct it:
first declaration of function
void fractal::calciterthread(vector<vector<iterc>> &matriz, int desdepos, int hastapos, int idthread){ ... } in main loop
vector<vector<iterc>> res; res.resize(altopantalla); (int = 0; < altopantalla; i++){ res[i].resize(anchopantalla); } int numthreads = 10; vector<thread> workers(numthreads); (int = 0; < numthreads; i++){ //here diferent try thread workers[i] (calciterthread, ref(res), inicio, fin, i)); // error: expresion must have constant value workers[i] = thread(calciterthread, ref(res), inicio, fin, i)); // error: no instance of constructor "std::thread::thread" matches argument list } ...rest of code... thanks clarify
try this:
#include <functional> #include <thread> #include <vector> // ... int numthreads = 10; std::vector<std::thread> workers; (int = 0; != numthreads; ++i) { workers.emplace_back(calciterthread, std::ref(res), inicia, fin, i); } (auto & t : workers) { t.join(); }
Comments
Post a Comment