dimanche 24 avril 2016

quick_exit() not available

I was trying some thread codes and I was though of using quick_exit function to terminate the program without clean up the resource, below is my code.

#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;
}

compiling using GCC 5.3.0 and the command i have used

g++ -std=c++11 pracrise.cpp -lpthread

thread model:posix

Am i missing anything i opened the header file of cstdlib the quick_exit is there.

C:\Program Files\mingw64>g++ -std=c++11 pracrise.cpp -lpthread
pracrise.cpp: In function 'int main()':
pracrise.cpp:25:2: error: 'quick_exit' is not a member of 'std'
  std::quick_exit(0);
  ^

Aucun commentaire:

Enregistrer un commentaire