summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/30_threads/thread/cons
diff options
context:
space:
mode:
authorChris Fairles <chris.fairles@gmail.com>2008-09-13 00:32:37 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2008-09-13 00:32:37 +0000
commit46e113bf2b767b2f2d488c68b18416bd5672ae21 (patch)
treef1b80ccc46845ad9f382edf7149e9088a80f68c5 /libstdc++-v3/testsuite/30_threads/thread/cons
parent8270e80020ae8387c24f212c29d5306c38569984 (diff)
downloadgcc-46e113bf2b767b2f2d488c68b18416bd5672ae21.tar.gz
thread: New.
2008-09-12 Chris Fairles <chris.fairles@gmail.com> Benjamin Kosnik <bkoz@redhat.com> * include/std/thread: New. * include/Makefile.am: Update. * include/Makefile.in: Regenerate. * src/thread.cc: New. * src/Makefile.am: Update. * src/Makefile.in: Regenerate. * acinclude.m4: Add check for nanosleep. * configure.ac: Call it. * configure: Regenerate. * config.h.in: Likewise. * config/abi/pre/gnu.ver: Add exports. * doc/doxygen/user.cfg.in: Add thread header. * testsuite/lib/libstdc++.exp (check_v3_target_nanosleep): Add. * testsuite/lib/dg-options.exp (dg-require-nanosleep): Add. * testsuite/30_threads/thread/cons/1.cc: New. * testsuite/30_threads/thread/cons/2.cc: Likewise. * testsuite/30_threads/thread/cons/3.cc: Likewise. * testsuite/30_threads/thread/cons/4.cc: Likewise. * testsuite/30_threads/thread/algorithm/1.cc: Likewise. * testsuite/30_threads/thread/algorithm/2.cc: Likewise. * testsuite/30_threads/thread/member/1.cc: Likewise. * testsuite/30_threads/thread/member/2.cc: Likewise. * testsuite/30_threads/thread/member/3.cc: Likewise. * testsuite/30_threads/thread/this_thread/1.cc: Likewise. * testsuite/30_threads/thread/this_thread/2.cc: Likewise. * testsuite/30_threads/thread/this_thread/3.cc: Likewise. * testsuite/30_threads/thread/this_thread/4.cc: Likewise. * testsuite/30_threads/headers/thread/types_std_c++0x.cc: Likewise. * testsuite/30_threads/headers/thread/std_c++0x_neg.cc: Likewise. * testsuite/17_intro/headers/c++200x/all.cc: Add thread. * testsuite/17_intro/headers/c++200x/all_multiple_inclusion.cc: Add thread, condition_variable and mutex. Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com> From-SVN: r140332
Diffstat (limited to 'libstdc++-v3/testsuite/30_threads/thread/cons')
-rw-r--r--libstdc++-v3/testsuite/30_threads/thread/cons/1.cc58
-rw-r--r--libstdc++-v3/testsuite/30_threads/thread/cons/2.cc74
-rw-r--r--libstdc++-v3/testsuite/30_threads/thread/cons/3.cc98
-rw-r--r--libstdc++-v3/testsuite/30_threads/thread/cons/4.cc91
4 files changed, 321 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/1.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/1.cc
new file mode 100644
index 00000000000..a631e7eabf8
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/thread/cons/1.cc
@@ -0,0 +1,58 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+int main()
+{
+ bool test __attribute__((unused)) = true;
+
+ try
+ {
+ std::thread t;
+ VERIFY( !t.joinable() );
+ }
+ catch (const std::system_error&)
+ {
+ VERIFY( false );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/2.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/2.cc
new file mode 100644
index 00000000000..e53b088449a
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/thread/cons/2.cc
@@ -0,0 +1,74 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <utility> // std::ref
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+void
+free_function(std::thread::id& id)
+{
+ id = std::this_thread::get_id();
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ try
+ {
+ std::thread::id t1_id1;
+ std::thread t1(free_function, std::ref(t1_id1));
+ std::thread::id t1_id2 = t1.get_id();
+ VERIFY( t1.joinable() );
+ t1.join();
+ VERIFY( !t1.joinable() );
+ VERIFY( t1_id1 == t1_id2 );
+ }
+ catch (const std::system_error&)
+ {
+ VERIFY( false );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/3.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/3.cc
new file mode 100644
index 00000000000..3df7ad050b9
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/thread/cons/3.cc
@@ -0,0 +1,98 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <functional> // std::unary_function
+#include <utility> // std::ref
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+struct copyable : public std::unary_function<std::thread::id&, void>
+{
+ copyable() = default;
+ ~copyable() = default;
+ copyable(const copyable& c)
+ { ++copy_count; }
+
+ void operator()(std::thread::id& id) const
+ {
+ id = std::this_thread::get_id();
+ }
+
+ static int copy_count;
+};
+
+int copyable::copy_count = 0;
+
+void test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ try
+ {
+ std::thread::id t1_id1;
+ copyable c1;
+ std::thread t1(std::ref(c1), std::ref(t1_id1));
+ std::thread::id t1_id2 = t1.get_id();
+ VERIFY( t1.joinable() );
+ t1.join();
+ VERIFY( !t1.joinable() );
+ VERIFY( t1_id1 == t1_id2 );
+ VERIFY( copyable::copy_count == 0 );
+
+ std::thread::id t2_id1;
+ copyable c2;
+ std::thread t2(c2, std::ref(t2_id1));
+ std::thread::id t2_id2 = t2.get_id();
+ VERIFY( t2.joinable() );
+ t2.join();
+ VERIFY( !t2.joinable() );
+ VERIFY( t2_id1 == t2_id2 );
+ VERIFY( copyable::copy_count > 0 );
+ }
+ catch (const std::system_error&)
+ {
+ VERIFY( false );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/4.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/4.cc
new file mode 100644
index 00000000000..76fc9ec3e45
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/thread/cons/4.cc
@@ -0,0 +1,91 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <functional> // std::unary_function
+#include <utility> // std::ref, std::cref
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+struct noncopyable : std::unary_function<std::thread::id&, void>
+{
+ noncopyable() = default;
+ ~noncopyable() = default;
+ noncopyable(const noncopyable&) = delete;
+ noncopyable& operator=(const noncopyable&) = delete;
+ void operator()(std::thread::id& id) const
+ {
+ id = std::this_thread::get_id();
+ }
+};
+
+void test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ try
+ {
+ std::thread::id t1_id1;
+ noncopyable nc1;
+ std::thread t1(std::ref(nc1), std::ref(t1_id1));
+ std::thread::id t1_id2 = t1.get_id();
+ VERIFY( t1.joinable() );
+ t1.join();
+ VERIFY( !t1.joinable() );
+ VERIFY( t1_id1 == t1_id2 );
+
+ std::thread::id t2_id1;
+ noncopyable nc2;
+ std::thread t2(std::cref(nc2), std::ref(t2_id1));
+ std::thread::id t2_id2 = t2.get_id();
+ VERIFY( t2.joinable() );
+ t2.join();
+ VERIFY( !t2.joinable() );
+ VERIFY( t2_id1 == t2_id2 );
+ }
+ catch(const std::system_error&)
+ {
+ VERIFY( false );
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ test03();
+ return 0;
+}