Say we have a very basic code to check an elapsed interval
#include <iostream>
#include <chrono>
int main()
{
auto start = std::chrono::steady_clock::now();
// some work
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end-start;
std::cout << "The interval is " << diff.count() << "\n";
}
Does each call to std::chrono::steady_clock::now() block other threads ? Is it considered lock free, or even wait free ? Does a call to std::chrono::steady_clock::now() ever starve or block any other thread ?
I am most interested in what the specification guarantees for std::chrono::steady_clock::now() . If it does not guarantee it to be wait free, is there any way to get a tick of a monotonic clock on MSVC/gcc/clang that is guaranteed to be wait free ?