Modify

Ticket #5418 (closed Bugs: fixed)

Opened 3 years ago

Last modified 3 years ago

Error in asio example: tick_count_timer

Reported by: Peter Grimstrup Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

The method less_than(t1, t2) returns true if called with t1 == t2.

static bool less_than(const time_type& t1, const time_type& t2)
{
    return (t2.ticks_ - t1.ticks_) < static_cast<DWORD>(1 << 31);
}

I suggest replacing with the correct (and maybe a bit more efficient):

static bool less_than(const time_type& t1, const time_type& t2)
{
    return (static_cast<long>(t2.ticks_) - static_cast<long>(t1.ticks_)) > 0;
}

Attachments

tick_count_timer.cpp Download (6.4 KB) - added by Ross MacGregor <gordonrossmacgregor@…> 3 years ago.
Updated example file: tick_count_timer.cpp

Change History

Changed 3 years ago by Ross MacGregor <gordonrossmacgregor@…>

Updated example file: tick_count_timer.cpp

comment:1 Changed 3 years ago by Ross MacGregor <gordonrossmacgregor@…>

I've discovered a more serious problem. Methods tick_count_traits::subtract will return a large overflow value if t2 > t1. This happens periodically in the timer_queue and causes the timer to stop working for a long period of time.

I've attached my solution to the problem. Basically, I changed duration_type to be a signed value that is reflected in the call to the method to_posix_duration. It may be possible to reduce my subtract method to something less complicated. I've also included a small test for tick_count_traits in the example.

comment:2 Changed 3 years ago by chris_kohlhoff

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

Fixed in release branch as of [72428].

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.