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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -