summaryrefslogtreecommitdiff
path: root/test/std/thread/thread.threads/thread.thread.class/thread.thread.member
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/thread/thread.threads/thread.thread.class/thread.thread.member')
-rw-r--r--test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp73
-rw-r--r--test/std/thread/thread.threads/thread.thread.class/thread.thread.member/get_id.pass.cpp57
-rw-r--r--test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp54
-rw-r--r--test/std/thread/thread.threads/thread.thread.class/thread.thread.member/joinable.pass.cpp54
-rw-r--r--test/std/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp54
-rw-r--r--test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp58
6 files changed, 350 insertions, 0 deletions
diff --git a/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
new file mode 100644
index 000000000000..f4a4d1f777f1
--- /dev/null
+++ b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <thread>
+
+// class thread
+
+// void detach();
+
+#include <thread>
+#include <atomic>
+#include <cassert>
+
+std::atomic_bool done = ATOMIC_VAR_INIT(false);
+
+class G
+{
+ int alive_;
+ bool done_;
+public:
+ static int n_alive;
+ static bool op_run;
+
+ G() : alive_(1), done_(false)
+ {
+ ++n_alive;
+ }
+
+ G(const G& g) : alive_(g.alive_), done_(false)
+ {
+ ++n_alive;
+ }
+ ~G()
+ {
+ alive_ = 0;
+ --n_alive;
+ if (done_) done = true;
+ }
+
+ void operator()()
+ {
+ assert(alive_ == 1);
+ assert(n_alive >= 1);
+ op_run = true;
+ done_ = true;
+ }
+};
+
+int G::n_alive = 0;
+bool G::op_run = false;
+
+int main()
+{
+ {
+ G g;
+ std::thread t0(g);
+ assert(t0.joinable());
+ t0.detach();
+ assert(!t0.joinable());
+ while (!done) {}
+ assert(G::op_run);
+ assert(G::n_alive == 1);
+ }
+ assert(G::n_alive == 0);
+}
diff --git a/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/get_id.pass.cpp b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/get_id.pass.cpp
new file mode 100644
index 000000000000..5cca7b0b66b8
--- /dev/null
+++ b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/get_id.pass.cpp
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <thread>
+
+// class thread
+
+// id get_id() const;
+
+#include <thread>
+#include <new>
+#include <cstdlib>
+#include <cassert>
+
+class G
+{
+ int alive_;
+public:
+ static int n_alive;
+ static bool op_run;
+
+ G() : alive_(1) {++n_alive;}
+ G(const G& g) : alive_(g.alive_) {++n_alive;}
+ ~G() {alive_ = 0; --n_alive;}
+
+ void operator()()
+ {
+ assert(alive_ == 1);
+ assert(n_alive >= 1);
+ op_run = true;
+ }
+};
+
+int G::n_alive = 0;
+bool G::op_run = false;
+
+int main()
+{
+ {
+ G g;
+ std::thread t0(g);
+ std::thread::id id0 = t0.get_id();
+ std::thread t1;
+ std::thread::id id1 = t1.get_id();
+ assert(t0.get_id() != id1);
+ assert(t1.get_id() == std::thread::id());
+ t0.join();
+ }
+}
diff --git a/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
new file mode 100644
index 000000000000..0512e49dcb33
--- /dev/null
+++ b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/join.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <thread>
+
+// class thread
+
+// void join();
+
+#include <thread>
+#include <new>
+#include <cstdlib>
+#include <cassert>
+
+class G
+{
+ int alive_;
+public:
+ static int n_alive;
+ static bool op_run;
+
+ G() : alive_(1) {++n_alive;}
+ G(const G& g) : alive_(g.alive_) {++n_alive;}
+ ~G() {alive_ = 0; --n_alive;}
+
+ void operator()()
+ {
+ assert(alive_ == 1);
+ assert(n_alive >= 1);
+ op_run = true;
+ }
+};
+
+int G::n_alive = 0;
+bool G::op_run = false;
+
+int main()
+{
+ {
+ G g;
+ std::thread t0(g);
+ assert(t0.joinable());
+ t0.join();
+ assert(!t0.joinable());
+ }
+}
diff --git a/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/joinable.pass.cpp b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/joinable.pass.cpp
new file mode 100644
index 000000000000..b97839c32184
--- /dev/null
+++ b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/joinable.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <thread>
+
+// class thread
+
+// bool joinable() const;
+
+#include <thread>
+#include <new>
+#include <cstdlib>
+#include <cassert>
+
+class G
+{
+ int alive_;
+public:
+ static int n_alive;
+ static bool op_run;
+
+ G() : alive_(1) {++n_alive;}
+ G(const G& g) : alive_(g.alive_) {++n_alive;}
+ ~G() {alive_ = 0; --n_alive;}
+
+ void operator()()
+ {
+ assert(alive_ == 1);
+ assert(n_alive >= 1);
+ op_run = true;
+ }
+};
+
+int G::n_alive = 0;
+bool G::op_run = false;
+
+int main()
+{
+ {
+ G g;
+ std::thread t0(g);
+ assert(t0.joinable());
+ t0.join();
+ assert(!t0.joinable());
+ }
+}
diff --git a/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp
new file mode 100644
index 000000000000..c8807a965c44
--- /dev/null
+++ b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <thread>
+
+// class thread
+
+// native_handle_type native_handle();
+
+#include <thread>
+#include <new>
+#include <cstdlib>
+#include <cassert>
+
+class G
+{
+ int alive_;
+public:
+ static int n_alive;
+ static bool op_run;
+
+ G() : alive_(1) {++n_alive;}
+ G(const G& g) : alive_(g.alive_) {++n_alive;}
+ ~G() {alive_ = 0; --n_alive;}
+
+ void operator()()
+ {
+ assert(alive_ == 1);
+ assert(n_alive >= 1);
+ op_run = true;
+ }
+};
+
+int G::n_alive = 0;
+bool G::op_run = false;
+
+int main()
+{
+ {
+ G g;
+ std::thread t0(g);
+ pthread_t pid = t0.native_handle();
+ assert(pid != 0);
+ t0.join();
+ }
+}
diff --git a/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp
new file mode 100644
index 000000000000..49d4618e86ad
--- /dev/null
+++ b/test/std/thread/thread.threads/thread.thread.class/thread.thread.member/swap.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <thread>
+
+// class thread
+
+// void swap(thread& t);
+
+#include <thread>
+#include <new>
+#include <cstdlib>
+#include <cassert>
+
+class G
+{
+ int alive_;
+public:
+ static int n_alive;
+ static bool op_run;
+
+ G() : alive_(1) {++n_alive;}
+ G(const G& g) : alive_(g.alive_) {++n_alive;}
+ ~G() {alive_ = 0; --n_alive;}
+
+ void operator()()
+ {
+ assert(alive_ == 1);
+ assert(n_alive >= 1);
+ op_run = true;
+ }
+};
+
+int G::n_alive = 0;
+bool G::op_run = false;
+
+int main()
+{
+ {
+ G g;
+ std::thread t0(g);
+ std::thread::id id0 = t0.get_id();
+ std::thread t1;
+ std::thread::id id1 = t1.get_id();
+ t0.swap(t1);
+ assert(t0.get_id() == id1);
+ assert(t1.get_id() == id0);
+ t1.join();
+ }
+}