Opened 8 years ago

Closed 7 years ago

#3178 closed Bugs (fixed)

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:


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 (0)

Change History (4)

comment:1 Changed 8 years ago by viboes

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

comment:2 Changed 7 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)

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 7 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 7 years ago by anthonyw

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

Fixed on trunk.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain anthonyw.
The resolution will be deleted. Next status will be 'reopened'.

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

Note: See TracTickets for help on using tickets.