Skip to content

Commit 4f4d6c8

Browse files
committed
[libcxx testing] Remove ALLOW_RETRIES from sleep_until.pass.cpp
Operating systems are best effort by default, so we cannot assume that sleep-like APIs return as soon as we'd like. Even if a sleep-like API returns when we want it to, the potential for preemption means that attempts to measure time are subject to delays.
1 parent a832fc4 commit 4f4d6c8

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

libcxx/test/std/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88
//
99
// UNSUPPORTED: libcpp-has-no-threads
10-
// ALLOW_RETRIES: 2
1110

1211
// <thread>
1312

@@ -22,16 +21,15 @@
2221

2322
int main(int, char**)
2423
{
25-
typedef std::chrono::system_clock Clock;
26-
typedef Clock::time_point time_point;
27-
std::chrono::milliseconds ms(500);
28-
time_point t0 = Clock::now();
29-
std::this_thread::sleep_until(t0 + ms);
30-
time_point t1 = Clock::now();
31-
std::chrono::nanoseconds ns = (t1 - t0) - ms;
32-
std::chrono::nanoseconds err = 5 * ms / 100;
33-
// The time slept is within 5% of 500ms
34-
assert(std::abs(ns.count()) < err.count());
24+
typedef std::chrono::system_clock Clock;
25+
typedef Clock::time_point time_point;
26+
std::chrono::milliseconds ms(500);
27+
time_point t0 = Clock::now();
28+
std::this_thread::sleep_until(t0 + ms);
29+
time_point t1 = Clock::now();
30+
// NOTE: Operating systems are (by default) best effort and therefore we may
31+
// have slept longer, perhaps much longer than we requested.
32+
assert(t1 - t0 >= ms);
3533

3634
return 0;
3735
}

0 commit comments

Comments
 (0)