Opened 11 years ago

Closed 7 years ago

#6377 closed Bugs (fixed)

Condition variable blocks when changing time

Reported by: Johan Borkhuis <johan@…> Owned by: viboes
Milestone: Boost 1.60.0 Component: thread
Version: Boost 1.47.0 Severity: Problem
Keywords: condition variable Cc:

Description

I am using Linux on an ARM system, running Boost 1.47. My application needs accurate timing, and for this I use a POSIX timer using SIGRTMIN. This part is not something that I can control, it is an external library that implements this. I use condition variables as a timing mechanism within my software.

When I use condition variables without the POSIX timer there is no problem. The timing continues correctly, even if I change the time forward or backward.

When I start the POSIX timer the condition variable does not time-out when I change the time backward. It only times out when the original time (plus timeout) is reached.

When I changed the clock of the pthread condition variable to monotonic (call to pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC)) the result was OK again.

Attached is a test application that shows the problem and implements a solution. This solution is not within the Boost library but directly as a POSIX condition variable. Options to the test application:

-b: use boost condition variable
-s: generate POSIX signals

When running the testapplication with -bs the application will stop reporting when the time is changed backwards. When the time is set back to a time after the time the time was changed the application will continue.

Attachments (1)

clocktest.cpp (5.0 KB ) - added by Johan Borkhuis <johan@…> 11 years ago.
Demo application showing the problem

Download all attachments as: .zip

Change History (13)

by Johan Borkhuis <johan@…>, 11 years ago

Attachment: clocktest.cpp added

Demo application showing the problem

comment:1 by Johan Borkhuis <johan@…>, 11 years ago

Component: interprocessthread
Owner: changed from Ion Gaztañaga to Anthony Williams

comment:2 by anonymous, 10 years ago

I also have the same issue.

comment:3 by viboes, 10 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

Boost.Thread provides timed functions based on a Boost.Chrono. Using the steady_clock should solve your problem. The legacy time-based functions will be deprecated soon. Please let me know if this solves your problem.

comment:4 by viboes, 10 years ago

Resolution: wontfix
Status: assignedclosed

comment:5 by viboes, 10 years ago

Milestone: To Be Determined

comment:6 by viboes, 7 years ago

Milestone: To Be Determined
Resolution: wontfix
Status: closedreopened

I'm writing a patch that uses pthread_condattr_setclock. As I said I have no platform providing it (I'm using MacOS). The user will need to define BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC until I find a way to detect it.

Is there any one that can test it?

comment:7 by viboes, 7 years ago

Milestone: To Be DeterminedBoost 1.60.0

comment:8 by viboes, 7 years ago

Status: reopenednew

comment:9 by viboes, 7 years ago

Milestone: Boost 1.60.0To Be Determined

comment:10 by viboes, 7 years ago

Status: newassigned

comment:11 by viboes, 7 years ago

Milestone: To Be DeterminedBoost 1.60.0
Note: See TracTickets for help on using tickets.