Anyone know if std::chrono functions are blocking?

Hi all,

I’m googling trying to find out whether std::chrono::high_resoloution_clock::now() is safe to call from the audio/callback thread or whether it exhibits blocking behaviour by requested system time from the OS.

Does anyone happen to know this off of the top of their heads ?

Cheers Jucers.

My guess would be that it uses whatever is usual on the platform in question to get the high resolution time. So on Windows maybe GetSystemFileTime and on Linux and maybe macOS clock_gettime. It would be pretty insane if those have blocking/unpredictable performance characteristics themselves…But of course the world is sometimes insane. By the way, why not use Juce’s Time class functions if you are using Juce anyway? With those you could also easily check what their implementations do.

I’m not aware of anywhere that claims to guarantee it’s safe, but I’ve used it in processing blocks before with considerable testing and no noticeable impact on performance on Windows and Mac.

Cheers guys. I’m going for std::chrono as I’d like to keep the classes in question reusable in JUCE free projects along with the plugin I’m currently working on.

@anthony-nicholls good to hear you’ve tested the usage of this a bit. That puts my mind at rest!

Most grateful chaps.

Josh

1 Like