RaG*_*__M 6 c++ gcc mingw-w64 c++11
我正在尝试一些线程代码,我虽然使用quick_exit函数来终止程序而不清理资源,下面是我的代码.
#include<future>
#include<iostream>
#include<thread> // std::thread, std::this_thread::sleep_for
#include<chrono>
#include<cstdlib>
using namespace std;
static void pause_thread(int n)
{
std::this_thread::sleep_for (std::chrono::seconds(n));
std::cout << "pause of " << n << " seconds ended\n";
}
int main()
{
std::cout << "Spawning and detaching 3 threads...\n";
std::thread (pause_thread,5).detach();
std::thread (pause_thread,8).detach();
std::thread (pause_thread,9).detach();
std::cout << "Done spawning threads.\n";
std::cout << "(the main thread will now pause for 2 seconds)\n";
// give the detached threads time to finish (but not guaranteed!):
pause_thread(2);
quick_exit(0); //here is the problem,was this a problem?
return 0;
}
Run Code Online (Sandbox Code Playgroud)
使用GCC 5.3.0和我使用过的命令进行编译
g++ -std=c++11 pracrise.cpp -lpthread
线程模型:posix
我失去了什么,我开的头文件cstdlib中quick_exit是存在的.
C:\Program Files\mingw64>g++ -std=c++11 pracrise.cpp -lpthread
pracrise.cpp: In function 'int main()':
pracrise.cpp:25:15: error: 'quick_exit' was not declared in this scope
quick_exit(0);
^
Run Code Online (Sandbox Code Playgroud)