c++ - Creating vector<thread> -
i trying create std::vector
of threads , run them.
code:
thread t1(calc, 95648, "t1"); thread t2(calc, 54787, "t2"); thread t3(calc, 42018, "t3"); thread t4(calc, 75895, "t4"); thread t5(calc, 81548, "t5"); vector<thread> threads { t1, t2, t3, t4, t5 };
error: "function std::thread::thread(const std::thread &)" (declared @ line 70 of "c:\program files (x86)\microsoft visual studio 12.0\vc\include\thread") cannot referenced -- deleted function
thread(const thread&) = delete;
what seems problem?
since threads aren't copyable, movable, recommend following approach:
std::vector<std::thread> threads; threads.emplace_back(calc, 95648, "t1"); threads.emplace_back(calc, 54787, "t2"); threads.emplace_back(calc, 42018, "t3"); threads.emplace_back(calc, 75895, "t4"); threads.emplace_back(calc, 81548, "t5");
Comments
Post a Comment