Subject: [boost] Condition Variables, POSIX signals and system time changes
From: Johan Borkhuis (johan_at_[hidden])
Date: 2012-01-10 02:35:54


I came across the following issue with condition variables. I don't know
if this is an issue with my application or with Boost condition variables.

First my setup. I am using Linux on an ARM system, running Boost 1.47. My
application needs accurate timing, and for this I use a POSIX timer using
SIGRTMIN. This part is not something that I can control, it is an external
library that implements this. I use condition variables are a timing
mechanism with in my software.

When I use condition variables without the POSIX timer there is no
problem. The timing continues correctly, even if I change the time forward
or backward.

When I start the POSIX timer the condition variable does not time-out when
I change the time backward. It only times out when the original time (plus
timeout) is reached.

The code I use to create the condition variable:

    boost::mutex m;
    boost::condition_variable cond;
    boost::unique_lock<boost::mutex> lk(m);
    cond.timed_wait(lk, duration);

I tested this also by extracting the code from Boost and implementing this
inline. This gave the same results. When I changed the clock of the
pthread condition variable to monotonic (call to
pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC)) the result was OK
again.

Is this an issue with my implementation, can I change some setting or is
this a (known) issue with the Boost condition variables?

If people are interested, I do have a small test application that I used
to test this issue that I can post here. I don't know however what the
policy is on this list wrt posting of attachments.

Kind regards,
    Johan Borkhuis