summaryrefslogtreecommitdiffstats
path: root/libcxx/test/thread/thread.threads/thread.thread.this
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-06-04 19:43:20 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-06-04 19:43:20 +0000
commit58a0a70fb2f13a04886038744feb5d26715de8f6 (patch)
treefa717aefc9bef5b1a3fbdd85393d402db40ee270 /libcxx/test/thread/thread.threads/thread.thread.this
parentbe7eaddc69d06fee3c55bc10c34144c35895e2b0 (diff)
downloadbcm5719-llvm-58a0a70fb2f13a04886038744feb5d26715de8f6.tar.gz
bcm5719-llvm-58a0a70fb2f13a04886038744feb5d26715de8f6.zip
Handle partial nanosleeps in this_thread::sleep_for
Signals may result in nanosleep returning with only some of the requested sleeping performed. Utilize nanosleep's "time-remaining" out parameter to continue sleeping when this occurs. llvm-svn: 210210
Diffstat (limited to 'libcxx/test/thread/thread.threads/thread.thread.this')
-rw-r--r--libcxx/test/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/libcxx/test/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp b/libcxx/test/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp
index d66db3f9f30..f66b9627985 100644
--- a/libcxx/test/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp
+++ b/libcxx/test/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp
@@ -15,9 +15,29 @@
#include <thread>
#include <cstdlib>
#include <cassert>
+#include <signal.h>
+#include <sys/time.h>
int main()
{
+ int ec;
+ struct sigaction action;
+ action.sa_handler = [](int) {};
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+
+ ec = sigaction(SIGALRM, &action, nullptr);
+ assert(!ec);
+
+ struct itimerval it;
+ it.it_interval = { 0 };
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 250000;
+ // This will result in a SIGALRM getting fired resulting in the nanosleep
+ // inside sleep_for getting EINTR.
+ ec = setitimer(ITIMER_REAL, &it, nullptr);
+ assert(!ec);
+
typedef std::chrono::system_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
OpenPOWER on IntegriCloud