|
Message-ID: <20160803112751.GX19691@port70.net> Date: Wed, 3 Aug 2016 13:27:52 +0200 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com Subject: Re: std::condition_variable::wait_for() breakage when system_clock changes C++11 MIPS * Ward Willats <musl@...dco.com> [2016-08-02 16:33:29 -0700]: > > We are running a C++ 11 app on a MIPS-based Linux/OpenWRT platform and linking against MUSCL 1.1.12 and libstdc++ v3. On cold boot, our system clock is often some random time in the future until ntpd or other software corrects it. This led to odd behavior and this experiment: > > If I use the busybox "date --set" to move our system's clock 24 hours into the future, and then call: > > std::condition_variable::wait_for() with the pre-canned std::chrono::duration, std::chrono::milliseconds( 120000 ), as a 2 minute wait timeout AND then... > > ...set the clock BACK 24 hours to the correct/current time with ntpd, wait_for() doesn't return after 2 minutes (assuming no notify() of course). (Presumably, wait_for() is using system_clock, and not steady_clock, and will fire in 24 hours + 2 minutes -- but I haven't waited to find out.) > > However, if I repeat this experiment and call std::condition_variable::wait_until() with a timeout time_point calculated as std::chrono::steady_clock::now() + std::chrono::milliseconds( 120000 ), which neatly binds a steady_clock ref into the time_point, it does indeed fire in 2 minutes after the clock is set back, as expected. > > In short, the std::condition_variable API that takes a std::chrono:duration does not work, but the one that takes a std::chrono::time_point does. > this is a libstdc++ issue so the gcc version matters. (i can see condvar related issues fixed in gcc bugzilla) there are several issues with the c++11 condvar timeout api e.g. http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#887 so i'd avoid using c++, it's just a broken abstraction layer on top of the pthreads api with poor specification.. meanwhile pthreads works fine and is portable.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.