This is an archive of the discontinued LLVM Phabricator instance.

libcxx std::condition_variable::wait_for() fix for when tick occurs during wait_for()
AbandonedPublic

Authored by bcain on Dec 13 2016, 7:54 AM.

Details

Summary

During std::condition_variable::wait_for(), we sample the system clock and then we sample the steady clock.

If a tick occurs after the system clock is sampled, but prior to when the steady clock is sampled, then the __do_timed_wait() may elapse the entire duration but the check at the end will fail and we'll return cv_status::no_timeout in error. In the thread.condition.condvar/wait_for test, this causes the test to fail for my hexagon target.

§ 30.5.1 states “Returns: cv_status::timeout if the relative timeout (30.2.4) specified by rel_time expired, otherwise cv_status::no_timeout.”

This proposed fix would sample the steady clock first. Now, if the tick elapses between the two the check would yield the same results as the underlying __do_timed_wait().

Diff Detail

Repository
rL LLVM

Event Timeline

bcain updated this revision to Diff 81233.Dec 13 2016, 7:54 AM
bcain retitled this revision from to libcxx std::condition_variable::wait_for() fix for when tick occurs during wait_for().
bcain updated this object.
bcain added reviewers: howard.hinnant, mclow.lists.
bcain set the repository for this revision to rL LLVM.
bcain added a subscriber: llvm-commits.
EricWF edited edge metadata.Dec 23 2016, 5:44 PM

I would love to know what platform you ran into this on.

Also I would love to see an attempt at writing a test for this.

bcain added a comment.Jan 3 2017, 8:18 AM

Also I would love to see an attempt at writing a test for this.

This was encountered on Hexagon. thread.condition.condvar/wait_for detects the failure, so to some extent a test already exists. I suspect that linux x86_64 would see the failure on that test if CONFIG_HZ were specified to be extremely high (> 40000).

An isolated, reliably failing test seems difficult/impossible since it would require the test case to simulate a system that knows quite a bit about the implementation ("system clock was just sampled in the wait_for context, so let's trigger a tick interrupt now"). A test case like this could be constructed but it would be a real challenge to integrate into the existing lit test suite.

EricWF accepted this revision.Jan 4 2017, 4:10 PM
EricWF edited edge metadata.
This revision is now accepted and ready to land.Jan 4 2017, 4:10 PM
bcain abandoned this revision.Jan 11 2018, 12:45 PM

this was committed by Marshall