Opened 12 years ago

Closed 11 years ago

#4327 closed Bugs (fixed)

warning C4244: conversion from '__int64' to 'long', possible loss of data

Reported by: viboes Owned by: Anthony Williams
Milestone: Boost 1.44.0 Component: thread
Version: Boost Development Trunk Severity: Problem
Keywords: Cc: viboes

Description

The following warning appears on msvc-9.0express:

compile-c-c++ ..\..\..\bin.v2\libs\thread\test\test_condition_notify_one.test\msvc-9.0express\debug\threading-multi\test_condition_notify_one.obj
test_condition_notify_one.cpp
C:\cygwin\boost\trunk\boost/thread/win32/thread_data.hpp(171) : warning C4244: 'argument' : conversion from '__int64' to 'long', possible loss of data
        test_condition_notify_one.cpp(116) : see reference to function template instantiation 'void boost::this_thread::sleep<boost::date_time::subsecond_duration<base_duration,frac_of_second>>(const TimeDuration &)' being compiled
        with
        [
            base_duration=boost::posix_time::time_duration,
            frac_of_second=0x03e8,
            TimeDuration=boost::date_time::subsecond_duration<boost::posix_time::time_duration,0x03e8>
        ]

The context is the call to pin_to_zero when the duration is stored on something larger than a long.

        template<typename TimeDuration>
        inline void sleep(TimeDuration const& rel_time)
        {
            interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
        }

I guest that we need another pin_to_zero overloading or making the pin_to_zero generic.

Change History (14)

comment:1 by viboes, 12 years ago

In addition the function interruptible_wait needs to be refactored when the number of milliseconds can not be hold on an unsigned long.

comment:2 by viboes, 12 years ago

Cc: viboes added

comment:3 by James_E_K@…, 12 years ago

I got rid of the warning by adding this after the existing pin_to_zero:

inline int64_t pin_to_zero(int64_t value) {

return (value<0)?0ull:(int64_t)value;

}

And adding this new interruptable_wait function:

inline void interruptible_wait(int64_t milliseconds) {

interruptible_wait(detail::win32::invalid_handle_value,milliseconds);

}

Whether or not this properly works with a value greater than ULONG_MAX is unknown.

comment:4 by sshock, 12 years ago

I'm running into this too. How can I find out when it will be fixed?

comment:5 by Jamie Kirkpatrick <jkp@…>, 12 years ago

The fix James_E_K suggested worked for me too....suggest something like this is rolled in as not many teams put up with that kind of warning from their code!

comment:6 by JFC, 12 years ago

I also have this problem with VS2010 and Boost 1.45

comment:7 by wsxedcrfv, 12 years ago

ok nice fix. but i get this error when i compile: LINK : fatal error LNK1561: Einstiegspunkt muss definiert werden.

i put the first function in thread_data.hpp at the and of the namespace detail and the second function at the end of the namespace this_thread.

im using visual c++ 2010 express and boost 1.45.

what have i done wrong?

comment:8 by anonymous, 12 years ago

Is it fixed in 1.46?

comment:9 by anonymous, 12 years ago

Can anyone tell me the best way to work around the issue for a simple call:

boost::this_thread::sleep(boost::posix_time::milliseconds(i_Milliseconds));

fails this way:

... : see reference to function template instantiation 'void boost::this_thread::sleep<boost::date_time::subsecond_duration<base_duration, frac_of_second>>(const TimeDuration &)' being compiled 1> with 1> [ 1> base_duration=boost::posix_time::time_duration, 1> frac_of_second=0x03e8, 1> TimeDuration=boost::date_time::subsecond_duration<boost::posix_time::time_duration,0x03e8> 1> ] ... thread_data.hpp(172): warning C4244: 'argument' : conversion from 'int64' to 'long', possible loss of data

Thanks!

in reply to:  8 comment:10 by anonymous, 12 years ago

Replying to anonymous:

Is it fixed in 1.46?

no

comment:11 by Pavel Machyniak <machyniak@…>, 12 years ago

While it will be fixed, here is workaround: convert to absolute time.

Example (boost 1.46):

void sleepMillisec( long milliseconds )
{
    boost::this_thread::sleep( 
        boost::get_system_time() + 
        boost::posix_time::milliseconds( std::max<long>(milliseconds,0) ) );
}

comment:12 by anonymous, 11 years ago

Why hasn't this been fixed yet (as of 1.46.1)? I've had to use the edit James_E_K suggested above since this warning started appearing. It breaks all of my boost::this_thread::sleep code since I treat warnings as errors.

comment:13 by anonymous, 11 years ago

when this will be fixed?

comment:14 by Anthony Williams, 11 years ago

Resolution: fixed
Status: newclosed

Fixed on trunk, revision 72303

Note: See TracTickets for help on using tickets.