Traditional Thread
C++ 11 supports multi-threading, for which we previously used pthread or boost. Standard C++ 11’s threading is based on boost::thread, now it’s cross platform and no dependency needed.
#include <thread>
#include <iostream>
int testThread()
{
std::cout << "I am a seperate thread...";
}
void main()
{
std::thread newThread(testThread);//now it's running
//do something else .... //
newThread.join();//before the ending, newThread should join
return;
}
The code is simple, the thread function will run right after the std::thread is declared.