boostorg / boostorg/thread

[cygwin] condition_variable::timed_wait tests fail in test_mutex

Open
#258 10 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
214
Forks
171
PR merge metrics
No merged PRs in 30d

Description

In test_mutex there are some simple tests that lock a mutex, then call timed_wait on a condition variable and the mutex. Given no other code will notify the condition variable, the tests (test_mutex.cpp:52 and test_mutex.cpp:91) expect to result to be false. On cygwin the result is sometimes true:

https://ci.appveyor.com/project/jeking3/thread/builds/20524620/job/axu9rgvpm2h1djgm?fullLog=true#L1626

I was able to reproduce this locally in the debugger by modifying timed_wait such that I could place a breakpoint on the failure:
```
Thread 17 "test_mutex" hit Breakpoint 1, boost::condition_variable_any::timed_wait > (this=0xffc4cb2c, m=..., abs_time=...)
at ../../../boost/thread/pthread/condition_variable.hpp:249
249 return result || true;
(gdb) l
244 detail::real_platform_timepoint before = detail::real_platform_clock::now();
245 const detail::platform_duration d(ts - before);
246 bool result = do_wait_until(m, detail::internal_platform_clock::now() + d);
247 detail::real_platform_timepoint after = detail::real_platform_clock::now();
248 if (ts > after)
249 return result || true;
250 return false;
251 #else
252 return do_wait_until(m, ts);
253 #endif
(gdb) p before
$1 = {dur = {ts_val = {tv_sec = 1543097563, tv_nsec = 498393000}}}
(gdb) p d
$2 = {ts_val = {tv_sec = 0, tv_nsec = 598000000}}
(gdb) p after
$3 = {dur = {ts_val = {tv_sec = 1543097564, tv_nsec = 96388700}}}
(gdb) p result
$4 = false
(gdb) p after - before
[New Thread 27380.0x74a4]
$5 = {ts_val = {tv_sec = 0, tv_nsec = 597995700}}
(gdb) p ts
$6 = {dur = {ts_val = {tv_sec = 1543097564, tv_nsec = 96393000}}}
```
The `after` time is 4300us before the end of `ts` which is the time point that should have passed. This likely means there is a rounding error somewhere, either in the time handling of boost.thread or down in cygwin.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.