Boost logo

Boost Users :

Subject: [Boost-users] this_thread::sleep hangs on local clock change
From: Goldshmidt, Mark (MGoldshmidt_at_[hidden])
Date: 2010-10-25 06:33:55


Hello,

We're using boost::thread library in a consumer application.
Part of the requirements for the application is 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 in release build, but not in debug.
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. Apparently
this is what causes different behavior in debug and release.
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

This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster_at_[hidden] and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.

An NDS Group Limited company. www.nds.com


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net