I am trying to write a program that launched an arbitrary number of threads for execution.
#include <iostream> #include <thread> using namespace std; void thf() { static int n = 0; n += 1; cout << "threads " << n << endl; n -= 1; return; } int main() { const int thrn = 10; thread *func_thread = new thread[thrn]; for(auto i = 0; i < thrn; i += 1) { func_thread[i].operator()(thf); //Здесь ошибка no member named 'operator()' in 'std::__1::thread' } for(auto i = 0; i < thrn; i += 1) { auto &x = func_thread[i]; if(x.joinable()) { x.join(); } } return 0; } UPD: Solution
thread **func_thread = new thread*[thrn]; for(auto i = 0; i < thrn; i += 1) { func_thread[i] = new thread(thf); }
Threadobject must also be launched using the.Start()method. - VladD