diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
commit | 3e519524c118651123eecf60c2bbc5d65ad9bac3 (patch) | |
tree | b2dd4168cfe448920a602cd7d2e40f95da187153 /libcxx/test/thread/thread.threads/thread.thread.this | |
parent | 9132c59d43b6c590c9bb33496eebf9f192d6857a (diff) | |
download | bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.tar.gz bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.zip |
libcxx initial import
llvm-svn: 103490
Diffstat (limited to 'libcxx/test/thread/thread.threads/thread.thread.this')
4 files changed, 105 insertions, 0 deletions
diff --git a/libcxx/test/thread/thread.threads/thread.thread.this/get_id.pass.cpp b/libcxx/test/thread/thread.threads/thread.thread.this/get_id.pass.cpp new file mode 100644 index 00000000000..d8391a68d6e --- /dev/null +++ b/libcxx/test/thread/thread.threads/thread.thread.this/get_id.pass.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <thread> + +// thread::id this_thread::get_id(); + +#include <thread> +#include <cassert> + +int main() +{ + std::thread::id id = std::this_thread::get_id(); + assert(id != std::thread::id()); +} 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 new file mode 100644 index 00000000000..13407858856 --- /dev/null +++ b/libcxx/test/thread/thread.threads/thread.thread.this/sleep_for.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <thread> + +// template <class Rep, class Period> +// void sleep_for(const chrono::duration<Rep, Period>& rel_time); + +#include <thread> +#include <cstdlib> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef Clock::time_point time_point; + typedef Clock::duration duration; + std::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + std::this_thread::sleep_for(ms); + time_point t1 = Clock::now(); + std::chrono::nanoseconds ns = (t1 - t0) - ms; + std::chrono::nanoseconds err = ms / 100; + // The time slept is within 1% of 500ms + assert(std::abs(ns.count()) < err.count()); +} diff --git a/libcxx/test/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp b/libcxx/test/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp new file mode 100644 index 00000000000..c117e12ac2a --- /dev/null +++ b/libcxx/test/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <thread> + +// template <class Clock, class Duration> +// void sleep_until(const chrono::time_point<Clock, Duration>& abs_time); + +#include <thread> +#include <cstdlib> +#include <cassert> + +int main() +{ + typedef std::chrono::system_clock Clock; + typedef Clock::time_point time_point; + typedef Clock::duration duration; + std::chrono::milliseconds ms(500); + time_point t0 = Clock::now(); + std::this_thread::sleep_until(t0 + ms); + time_point t1 = Clock::now(); + std::chrono::nanoseconds ns = (t1 - t0) - ms; + std::chrono::nanoseconds err = ms / 100; + // The time slept is within 1% of 500ms + assert(std::abs(ns.count()) < err.count()); +} diff --git a/libcxx/test/thread/thread.threads/thread.thread.this/yield.pass.cpp b/libcxx/test/thread/thread.threads/thread.thread.this/yield.pass.cpp new file mode 100644 index 00000000000..fcbd358cec8 --- /dev/null +++ b/libcxx/test/thread/thread.threads/thread.thread.this/yield.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <thread> + +// void this_thread::yield(); + +#include <thread> +#include <cassert> + +int main() +{ + std::this_thread::yield(); +} |