Boost logo

Boost :

Subject: [boost] [chrono] Possible bug in boost::chrono::process_real_cpu_clock::now() under Windows 32bits
From: ivan.lelann_at_[hidden]
Date: 2012-01-05 10:30:53


Hi,

As of 1.48 Boost.Chrono contains code below for boost::chrono::process_real_cpu_clock::now()
(boost\chrono\detail\inlined\win\process_cpu_clocks.hpp)

    clock_t c = ::clock();
    /* ... */
    return time_point(
      duration(c*(1000000000l/CLOCKS_PER_SEC))
    );

duration::rep is int64/nanoseconds, clock_t is long. This is VS2008, Win XP 32bits.

I think "c" should be cast to duration::rep before being multiplied.
I randomly get negative time_point and this seems to be fixed by replacing
"c" with "((duration::rep) (c))" in duration constructor :

        duration( ((duration::rep) (c)) *(1000000000l/CLOCKS_PER_SEC))

Can someone confirm my view and that the fix is correct ?

Regards,
Ivan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk