How do I start a new thread in parallel without pausing the main function?
Here is my code:
void someFunction { while(1);}
int main(){
thead *th = new thead(&someFunction);
thead.join();
return 0;
}
But program doesn’t stop
P.S. How run thread in parallel source
This call:
explicitely tells your program to wait until the function the
threadis executing, returns. Your function never returns, so you program never gets past this function call. You can start extra threads between the thread creation and the corresponding call tojoin(). For example:will spawn 3 threads that do absolutely nothing. If the functions passed to the threads do return, this is what you want to do.
If you want to have the task run and the main program exit before that, you will need to spawn a new process in a platform-dependent way, so that their execution is not stopped by your program exiting.