c++ - boost::this_thread::sleep() vs. nanosleep()? -


I recently came to the need to sleep on the existing thread for an exact period. By using nanosleep () or using boost :: this_thread :: sleep () I have two ways to do this on a POSIX platform.

In more curiosity than anything else, I was wondering what differences between the two approaches are, what is the difference in the accuracy, and whether to use the Boost approach not any reason?

nanosleep () approach:

#include & lt; Time.h> ... struct timespec sleep time; Struct timespec returnTime; SleepTime.tv_sec = 0; SleepTime.tv_nsec = 1000; Nanosleep (and sleep time, and return time);

Boost approach:

  #include & lt; Boost / date_time / posix_time / posix_time.hpp & gt; #include & lt; Boost / thread / thread.hpp & gt; ... Boost :: this_thread :: sleep (boost :: posix_time :: nanoseconds (1000));  

For some reasons, I think the reason for promotion:

< Ul>
  • Promotion: this_thread :: sleep () is an interruption point in promoting. Thread
  • Promotion: this_thread :: sleep () Drop-ins may be replaced by C ++ 0x std :: this_thread :: sleep_until () in the future
  • Why not - not using everything or threads in your project, then uses posix calls, then Nanoside () makes more sense.

    For precise, promote both on my system and call Nanosleep () the same system call, hrtimer_nanosleep () . I think the authors should try to get the highest accuracy on each system, and this is what happens to me, as nanosleep () provides.


    Comments