在我的程序中,有很多循环可以轻松地重写为多线程。基本上,对于每个应该是多线程的函数,我正在编写以下函数:
void func_to_threaded(int i_from, int i_to, int num_th, ...other_parameters)
{
int i_min = i_from;
int i_max = i_to;
int i_inc = i_max / num_th;
i_max = i_max % num_th + i_inc;
thread* th_dens = new thread[num_th];
for (int i = 0; i < num_th; i++)
{
th_dens[i] = thread(func_one_thread, i_min, i_max, ...other_parameters);
i_min = i_max;
i_max += i_inc;
}
for (int i = 0; i < num_th; i++) th_dens[i].join();
delete[] th_dens;
}
有没有办法将其重写为对于表单的每个函数都是通用的
void func_one_thread(int i_min, int i_max, ...other_parameters)
最佳答案
关于c++ - 多线程包装器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40936306/