In my program there is lot of loops that can be easily rewritten into multithread. Basically for each function which should be multithreadd I am writing following function:
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;
}
Is there a way to rewrite this to be generic for every function of form
void func_one_thread(int i_min, int i_max, ...other_parameters)