Saturday, 7 September 2019

std::condition_variable will work correctly with std::chrono::steady_clock in GCC 10!

In a previous blog post I lamented the lack of proper support for std::chrono::steady_clock in libstdc++’s implementation of std::condition_variable. I’m pleased to say that this problem will be solved when GCC 10 is released.
In the end, I managed to guide the “Invent a new pthreads function” solution through the Austin Group, although my proposed pthread_cond_timedwaitonclock function became simply pthread_cond_clockwait and was joined by pthread_mutex_clocklock, pthread_rwlock_clockwrlock, pthread_rwlock_clockrdlock and sem_clockwait along the way. These new functions are available in glibc v2.30.
Once pthread_cond_clockwait was available in glibc, it was straightforward to fix libstdc++’s std::condition_variable to use it.
Thanks to Adhemerval Zanella for reviewing the new glibc functions and Jonathan Wakely for reviewing the libstdc++ changes.

No comments: