Opened 7 years ago

Closed 6 years ago

#5418 closed Bugs (fixed)

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:


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

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

Download all attachments as: .zip

Change History (3)

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

Attachment: tick_count_timer.cpp added

Updated example file: tick_count_timer.cpp

comment:1 Changed 7 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 6 years ago by chris_kohlhoff

Resolution: fixed
Status: newclosed

Fixed in release branch as of [72428].

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain chris_kohlhoff.
The resolution will be deleted.

Add Comment

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

Note: See TracTickets for help on using tickets.