#include <iostream>
#include <thread>
using std::cout;
using std::endl;
void threadFunction()
{
cout << "Start threadFunction()" << endl;
std::this_thread::sleep_for(std::chrono::seconds(3));
cout << "End threadFunction()" << endl;
}
void threadControl()
{
cout << "Start threadControl()" << endl;
std::thread t(threadFunction);
t.detach();
std::this_thread::sleep_for(std::chrono::seconds(1));
cout << "End threadControl()" << endl;
}
int main()
{
threadControl();
cout << "main()" << endl;
std::this_thread::sleep_for(std::chrono::seconds(4));
cout << "End main()" << endl;
return 0;
}
/*
run:
Start threadControl()
Start threadFunction()
End threadControl()
main()
End threadFunction()
End main()
*/