Opened 11 years ago
Closed 7 years ago
#6377 closed Bugs (fixed)
Condition variable blocks when changing time
Reported by: | 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)
Change History (13)
by , 11 years ago
Attachment: | clocktest.cpp added |
---|
comment:1 by , 11 years ago
Component: | interprocess → thread |
---|---|
Owner: | changed from | to
comment:3 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
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 , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
comment:5 by , 10 years ago
Milestone: | To Be Determined |
---|
comment:6 by , 7 years ago
Milestone: | → To Be Determined |
---|---|
Resolution: | wontfix |
Status: | closed → reopened |
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 , 7 years ago
Milestone: | To Be Determined → Boost 1.60.0 |
---|
Add to develop branch https://github.com/boostorg/thread/commit/9f883f6ad7377b88b79fa70cc5de68cbfb0213e4
comment:8 by , 7 years ago
Status: | reopened → new |
---|
comment:9 by , 7 years ago
Milestone: | Boost 1.60.0 → To Be Determined |
---|
comment:10 by , 7 years ago
Status: | new → assigned |
---|
comment:11 by , 7 years ago
Milestone: | To Be Determined → Boost 1.60.0 |
---|
Please, could you try the develop branch
https://github.com/boostorg/thread/commit/8f5de1d7c34ff7248261874f273498a622bf76d4
comment:12 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Demo application showing the problem