Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Interrupt handling of std::this_thread::sleep_for

How do I handle interrupt of the following code?

    while (!isValid()) {
      std::cout << "looping again" << std::endl;
      std::this_thread::sleep_for(std::chrono::milliseconds(60000));
    }

The problem is when the control is inside the while loop and it goes to sleep and then I try to terminate the program by Ctrl+C (SIGINT), it doesn't terminate but the message "looping again" is printed. I assume that with SIGINT the sleep is interrupted but as there is no interrupt handler, no proper action is taken. I could't find a standard way of handling the interrupt of sleep_for.

Comments