This call:
thread.join();
explicitely tells your program to wait until the function the thread
is 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 to join()
. For example:
#include <thread>
void someFunction() { for(volatile int x = 0; ; x = x){};}
int main()
{
std::thread t1(someFunction);
std::thread t2(someFunction);
std::thread t3(someFunction);
t1.join();
t2.join();
t3.join();
return 0;
}
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.