In an application i need to periodically read the monotonic and system clock of std::chrono right after each other with the smallest possible delay inbetween.
Like this:
#include <iostream>
#include <chrono>
int main() {
bool interrupted = false;
auto time_system = std::chrono::system_clock::now();
auto time_monoton = std::chrono::steady_clock::now();
if (interrupted) {
std::cout << "Thread had been interrupted between clock reading!" << std::endl;
}
else {
//do stuff
}
return 0;
}
Of course there is still a small chance that the program is interrupted by the operating system right inbetween capturing the clock values and then time_system
and time_monoton
will not be aquired directly after each other.
Is there e.g. a thread status variable available to reset before and check if a thread has been interrupted by the operating system inbetween a program section.
I found that boost::threads can throw a boost::thread_interrupted
-Exception, but i don't fully understand if this Exception is only thrown when some other thread activly calls the interrupt()-method or also when the OS is interrupting the prgroams process and their threads.
Is there a method within the STL or Boost to detect if a program got interrupted? (Besides the trivial solution to check monotonic clock before and after and define a reasonable threshold on a practical bases)