Boost logo

Boost Users :

Subject: [Boost-users] Sleeping a Boost.thread for some Boost.date_time nanoseconds
From: Emer Rodriguez Formisano (emer_at_[hidden])
Date: 2011-07-10 05:53:45

Good morning,

I want a boost thread to sleep for some nanoseconds. The following
code is a sample that compiles without errors. However, it does not
work as expected and I cannot figure out why. It seems that the
application get stacked when executes the instruction: sleep(time1)
and it does not execute any thing else.

#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time.hpp>
//Building options:
void replay()
    boost::posix_time::time_duration time1, time2;

    std::cout << boost::posix_time::to_simple_string(time1) << std::endl;

    std::cout << boost::posix_time::to_simple_string(time2) << std::endl;
int main(int argc, char* argv[])
    boost::thread replaythread(replay);
    return 0;

The BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG is a preprocessor definition
required in order to work with nanoseconds
The thread sleeps perfectly for 3 seconds if you remove the mentioned
definition from the building options and if you also comment out the
code related to nanoseconds (lines 15-17).

Thank you very much for your time

This question was also posted to stackoverflow

Emer Rodríguez Formisano

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at