Advertisement
Guest User

Untitled

a guest
Aug 27th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. void handler(
  2. const boost::system::error_code& error,
  3. int signal_number)
  4. {
  5. if (!error)
  6. {
  7. static bool first = true;
  8. if(first){
  9. std::cout << " A signal(SIGINT) occurred." << std::endl;
  10. // do something like writing data to a file
  11. first = false;
  12. }else{
  13. std::cout << " A signal(SIGINT) occurred, exiting...." << std::endl;
  14. exit(0);
  15. }
  16. }
  17. }
  18.  
  19. int main(){
  20. // Construct a signal set registered for process termination.
  21. boost::asio::io_service io;
  22. boost::asio::signal_set signals(io, SIGINT);
  23. // Start an asynchronous wait for one of the signals to occur.
  24. signals.async_wait(handler);
  25. io.run();
  26. size_t i;
  27. for(i=0;i<std::numeric_limits<size_t>::max();++i){
  28. // time stepping loop, do some computations
  29. }
  30. std::cout << i << std::endl;
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement