Modify

Ticket #3178 (closed Bugs: fixed)

Opened 5 years ago

Last modified 4 years ago

Sleep with negative time

Reported by: daniel Owned by: anthonyw
Milestone: Boost 1.40.0 Component: thread
Version: Boost 1.39.0 Severity: Regression
Keywords: thread sleep timespan negative Cc:

Description

When trying to sleep with a negative timespan it will result in almost infinite sleep.

Solution: in this_thread sleep, check for negative timespan before calling interruptible_wait.

Attachments

Change History

comment:1 Changed 4 years ago by viboes

As you state this is a regression, could you state on which version this was OK?

comment:2 Changed 4 years ago by marshall

I've got to concur with the OP (from libs/thread/win32/thread_data.hpp):

    namespace this_thread {
        template<typename TimeDuration>
        inline void sleep(TimeDuration const& rel_time)
        {
            interruptible_wait(static_cast<unsigned long>(rel_time.total_milliseconds()));
        }
    }

The problem here is the cast to unsigned long; that turns a small negative value into a large positive one. The question is, what should happen? Should the fn return immediately? Throw an exception?

On the pthread side, the code looks like:

    namespace this_thread {
        inline void sleep(TimeDuration const& rel_time)
        {
            this_thread::sleep(get_system_time()+rel_time);
        }
}

I don't know what happens if you pass a time in the past to sleep here, but the same questions as to how to handle the error apply.

comment:3 Changed 4 years ago by viboes

I don't think the low level functions must check for these on the past wait, for me this should be undefined behavior (the documentation should state this for all the timeout based operation). The user can always define its own function that do the check. If people consider that this is useful we could add some safe timeout based functions.

comment:4 Changed 4 years ago by anthonyw

  • Status changed from new to closed
  • Resolution set to fixed

Fixed on trunk.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.