Consider following pseudocode:
HANDLE Thread1 = CreateThread(Function1);
HANDLE Thread2 = CreateThread(Function2);
while(Program_Running) {
RunThread(Thread1);
RunThread(Thread2);
Function3();
WaitToFinish(Thread1);
WaitToFinish(Thread2);
Data = Function1_Result + Function1_Result + Function2_Result + Function3_Result;
};
To speedup process I decide to use multithreading, so I create 2 extra threads to do calculations, but they should be executed only when I need it, therefore it cannot be infinite loop. However creating new thread every iteration is quite slow. That's why I'm looking for a way how to restart thread. If that is not possible, what would be best way to execute threads only when I need them to, without having that overhead of recreating threads?
Thank you in advance.






