Index: pthread/thread.cpp =================================================================== --- pthread/thread.cpp (revision 79973) +++ pthread/thread.cpp (working copy) @@ -432,24 +432,37 @@ sleep_for(const chrono::nanoseconds& ns) { using namespace chrono; - if (ns >= nanoseconds::zero()) + boost::detail::thread_data_base* const thread_info=boost::detail::get_current_thread_data(); + + if(thread_info) { + unique_lock lk(thread_info->sleep_mutex); + while(cv_status::no_timeout==thread_info->sleep_condition.wait_for(lk,ns)) {} + } + else + { + if (ns >= nanoseconds::zero()) + { + + # if defined(BOOST_HAS_PTHREAD_DELAY_NP) timespec ts; ts.tv_sec = static_cast(duration_cast(ns).count()); ts.tv_nsec = static_cast((ns - seconds(ts.tv_sec)).count()); - -# if defined(BOOST_HAS_PTHREAD_DELAY_NP) BOOST_VERIFY(!pthread_delay_np(&ts)); -# elif defined(BOOST_HAS_NANOSLEEP) + # elif defined(BOOST_HAS_NANOSLEEP) + timespec ts; + ts.tv_sec = static_cast(duration_cast(ns).count()); + ts.tv_nsec = static_cast((ns - seconds(ts.tv_sec)).count()); // nanosleep takes a timespec that is an offset, not // an absolute time. nanosleep(&ts, 0); -# else + # else mutex mx; mutex::scoped_lock lock(mx); condition_variable cond; cond.wait_for(lock, ns); -# endif + # endif + } } } #endif