Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void handler(
- const boost::system::error_code& error,
- int signal_number)
- {
- if (!error)
- {
- static bool first = true;
- if(first){
- std::cout << " A signal(SIGINT) occurred." << std::endl;
- // do something like writing data to a file
- first = false;
- }else{
- std::cout << " A signal(SIGINT) occurred, exiting...." << std::endl;
- exit(0);
- }
- }
- }
- int main(){
- // Construct a signal set registered for process termination.
- boost::asio::io_service io;
- boost::asio::signal_set signals(io, SIGINT);
- // Start an asynchronous wait for one of the signals to occur.
- signals.async_wait(handler);
- io.run();
- size_t i;
- for(i=0;i<std::numeric_limits<size_t>::max();++i){
- // time stepping loop, do some computations
- }
- std::cout << i << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement