Using C ++ 11 Timeline with _USE_32BIT_TIME_T in

The project I'm working on requires me to use the preprocessor definition _USE_32BIT_TIME_T

. So I can't get rid of it. I also want to use a library chrono

for C ++ 11 for timing out. However, I cannot get it to work. Here is the code I am working on.

    std::mutex *lock = new std::mutex;
    std::condition_variable *cv = new std::condition_variable;
    std::unique_lock<std::mutex> ulock(*lock);

    auto start = std::chrono::high_resolution_clock::now();
    cv->wait_for(ulock, std::chrono::milliseconds(40));
    auto finish = std::chrono::high_resolution_clock::now();
    cout << std::chrono::duration_cast<std::chrono::nanoseconds>(finish - start).count() << "ns\n";

      

I am getting the following warning. It compiles but doesn't work as expected. It usually doesn't return with wait_for, or if it waits at any time.

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\chrono(749): warning C4244: '=' : conversion from '__int64' to 'time_t', possible loss of data
          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\condition_variable(73) : see reference to function template instantiation 'xtime std::_To_xtime<__int64,std::milli>(const std::chrono::duration<__int64,std::milli> &)' being compiled
          Main.cpp(24) : see reference to function template instantiation 'std::_Cv_status std::condition_variable::wait_for<__int64,std::milli>(std::unique_lock<std::mutex> &,const std::chrono::duration<__int64,std::milli> &)' being compiled

      

Is there a way to use chrono

from _USE_32BIT_TIME_T

on?

+3


source to share


2 answers


Apparently there is a bug in Visual Studio: http://connect.microsoft.com/VisualStudio/feedbackdetail/view/972033/std-chrono-and-use-32bit-time-t-dont-work-togther



I ended up using boost

C ++ 11 instead of the standard libraries.

+3


source


I have the same problem. I worked around this by changing wait_for to wait_until passing in the current time + whatever delay you want

xtime xt;
xtime_get(&xt, TIME_UTC);
xt.sec += 10;
cvTimeout.wait_until(lkTimeout, &xt);

      



http://en.cppreference.com/w/cpp/thread/condition_variable/wait_until

0


source







All Articles