Consider following example, On windows 7 icore7 laptop(VC++2010) and ubuntu 64bit 12.04 lte gcc 4.6.3
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread/thread.hpp>
typedef boost::posix_time::ptime Time;
typedef boost::posix_time::time_duration TimeDuration;
int main()
{
Time t1;
Time t2;
TimeDuration dt;
boost::posix_time::microseconds tosleep=boost::posix_time::microseconds(100);
for(int i=0;i<10;i++){
t1=boost::posix_time::microsec_clock::local_time();
//std::cout <<i << std::endl; // on win7 without this all outputs are 0
boost::this_thread::sleep( tosleep );
t2=boost::posix_time::microsec_clock::local_time();
dt = t2 - t1;
long long msec = dt.total_microseconds();
std::cout << msec << std::endl;
}
return 0;
}
I was expecting that my thread will sleep constantly 100 microsecond, but output is something weird :
=========== AND OUTPUT ==================
arm2arm@cudastartub:~$ g++ -O3 sleepme.cpp -lboost_thread
arm2arm@cudastartub:~$ ./a.out
726
346
312
311
513
327
394
311
306
445
Is boost has a some overhead? What I need for RealTime systems, where microseconds are important?