Hello,

We're using boost::thread library in a consumer application.
The application is required to continue operation when the user
changes local time. Our problem is that if local time is set backwards
X minutes during a call to this_thread::sleep(duration) the thread
sleeps for X minutes+duration.

This happens on MacOS with boost 1.44.0. On Windows behavior is correct.
I didn't have a chance to check other platforms.

I believe that the intention of this_thread::sleep(duration)
is to suspend thread execution for <duration> period regardless
of local clock setting, and provide consistent behavior across
all platforms and build configurations.

Looking into the code of libs/thread/src/pthread/thread.cpp
I see that problematic flow may occur in case of
detail::get_current_thread_data() is returning null. The "offendinng" code
tries to make sure that absolute point
in time (current time + requested delay) is reached using 5 attempts
and calculating necessary sleep duration each time. So if during
the first sleep local clock is set backwards, second sleep
will try to "compensate" for the new difference.
 
The simplest workaround for the problem I could think of is
to replace the first statement of the sleep(...) function:
  detail::thread_data_base* const thread_info=
       detail::get_current_thread_data();

with this one:
  detail::thread_data_base* const thread_info=
       get_or_make_current_thread_data();

Would it create any unwanted side effects? Is there a better way
to deal with is problem?

Thanks in advance,
Mark Goldshmidt