diff options
Diffstat (limited to 'libstdc++-v3/testsuite/30_threads/thread')
23 files changed, 1344 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 000000000..94f1d7db4 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/1.cc @@ -0,0 +1,52 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +// thread default cons works +// thread default cons no throw +// thread default cons not joinable +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 000000000..87b4476f6 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/2.cc @@ -0,0 +1,73 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <functional> // std::ref +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +void +free_function(std::thread::id& id) +{ + id = std::this_thread::get_id(); +} + +// thread::id default cons +// thread::id copy ctor +// thread variadic cons, c++ function +// thread variadic cons joinable +// thread join +// thread join postcondition not joinable +// thread join postcondition function called correctly +// this_thread::get_id +void test02() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread::id id1; + std::thread t(free_function, std::ref(id1)); + std::thread::id id2 = t.get_id(); + VERIFY( t.joinable() ); + t.join(); + VERIFY( !t.joinable() ); + VERIFY( id1 == 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 000000000..b35f28eea --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/3.cc @@ -0,0 +1,92 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <functional> // std::unary_function, 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; + +// same as 2, but function is copyable function object +// thread variadic cons not copied when std::ref +// thread variadic cons copied when not std::ref +// no errors +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 000000000..982a49b05 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/4.cc @@ -0,0 +1,87 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <functional> // std::unary_function, 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(); + } +}; + +// same as 3, but function is noncopyable function object +// thread variadic cons not copied when std::ref +// thread variadic cons copied when not std::ref +// thread variadic cons not copied when std::cref +// thread variadic cons copied when not std::cref +// no errors +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; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/5.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/5.cc new file mode 100644 index 000000000..000e558c9 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/5.cc @@ -0,0 +1,77 @@ +// { 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) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <functional> // std::unary_function, std::ref +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +struct nonconst : public std::unary_function<std::thread::id&, void> +{ + void operator()(std::thread::id& id) + { + id = std::this_thread::get_id(); + } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread::id t1_id1; + nonconst 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 ); + + std::thread::id t2_id1; + nonconst 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 ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/6.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/6.cc new file mode 100644 index 000000000..b21892cd8 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/6.cc @@ -0,0 +1,65 @@ +// { 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) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +bool f_was_called = false; + +void f() +{ + f_was_called = true; +} + +// thread non-variadic cons, c++ function +// thread join +// thread join postcondition function called correctly +// no errors +void test06() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread t(f); + t.join(); + VERIFY( f_was_called ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/7.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/7.cc new file mode 100644 index 000000000..5aa4c32a2 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/7.cc @@ -0,0 +1,72 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +bool functor_was_called = false; + +struct copyable +{ + copyable() = default; + ~copyable() = default; + copyable(const copyable& c) = default; + copyable& operator=(const copyable&) = default; + + void operator()() const + { + functor_was_called = true; + } +}; + +// same as 6, but function is copyable function object passed by reference +void test07() +{ + bool test __attribute__((unused)) = true; + + try + { + copyable c; + copyable& rc = c; + std::thread t(rc); + t.join(); + VERIFY( functor_was_called ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/8.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/8.cc new file mode 100644 index 000000000..b0ed1eda1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/8.cc @@ -0,0 +1,72 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +bool functor_was_called = false; + +struct moveable +{ + moveable() = default; + ~moveable() = default; + moveable(const moveable& c) = delete; + moveable& operator=(const moveable&) = delete; + moveable(moveable&&) { } + + void operator()() const + { + functor_was_called = true; + } +}; + +// same as 6, but function object is movable +void test08() +{ + bool test __attribute__((unused)) = true; + + try + { + moveable m; + std::thread t(std::move(m)); + t.join(); + VERIFY( functor_was_called ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/9.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/9.cc new file mode 100644 index 000000000..04394b262 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/9.cc @@ -0,0 +1,83 @@ +// { 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) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +int total = 0; + +// Functor has internal state. +struct moveable +{ + int i; + + moveable() = default; + ~moveable() = default; + moveable(const moveable& c) = delete; + moveable& operator=(const moveable&) = delete; + + moveable(int j): i(j) { } + moveable(moveable&& m): i(m.i) { } + + void operator()() const { total += i; } +}; + +// Two threads called by same functor type, different functor objects +// that have different state. Make sure each thread calls the correct +// functor. +void test09() +{ + bool test __attribute__((unused)) = true; + + try + { + // first + moveable m1(60); + std::thread t1(std::move(m1)); + t1.join(); + VERIFY( total == 60 ); + + // second + moveable m2(600); + std::thread t2(std::move(m2)); + t2.join(); + VERIFY( total == 660 ); // Not 120... + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/assign_neg.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/assign_neg.cc new file mode 100644 index 000000000..406d16085 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/assign_neg.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009, 2010 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <thread> + +void test01() +{ + // assign + typedef std::thread test_type; + test_type t1; + test_type t2; + t1 = t2; // { dg-error "deleted" } +} + +// { dg-prune-output "include" } diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/copy_neg.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/copy_neg.cc new file mode 100644 index 000000000..9d8681d47 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/copy_neg.cc @@ -0,0 +1,33 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009, 2010 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <thread> + +void test01() +{ + // copy + typedef std::thread test_type; + test_type t1; + test_type t2(t1); // { dg-error "deleted" } +} + +// { dg-prune-output "include" } diff --git a/libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc new file mode 100644 index 000000000..f3f5c7baf --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc @@ -0,0 +1,79 @@ +// { 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) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <utility> +#include <testsuite_hooks.h> + +bool functor_was_called = false; + +struct moveable +{ + moveable() = default; + ~moveable() = default; + moveable(const moveable& c) = delete; + moveable& operator=(const moveable&) = delete; + moveable(moveable&&) { } + + void operator()() const { } +}; + + +void test01() +{ + bool test __attribute__((unused)) = true; + + moveable m; + std::thread b(std::move(m)); + std::thread::id id_initial = b.get_id(); + VERIFY( b.joinable() ); + VERIFY( id_initial != std::thread::id() ); + + // copy move construct + // copied new thread old id, original thread default id + std::thread c(std::move(b)); + VERIFY( c.joinable() ); + VERIFY( c.get_id() == id_initial ); + VERIFY( !b.joinable() ); + VERIFY( b.get_id() == std::thread::id() ); + + // copy move assign + std::thread d; + VERIFY( !d.joinable() ); + VERIFY( d.get_id() == std::thread::id() ); + d = std::move(c); + VERIFY( d.joinable() ); + VERIFY( d.get_id() == id_initial ); + VERIFY( !c.joinable() ); + VERIFY( c.get_id() == std::thread::id() ); + + d.join(); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/id/hash.cc b/libstdc++-v3/testsuite/30_threads/thread/id/hash.cc new file mode 100644 index 000000000..86acac84c --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/id/hash.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2010 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <thread> + +// thread::id hash +std::hash<std::thread::id> h1; diff --git a/libstdc++-v3/testsuite/30_threads/thread/id/operators.cc b/libstdc++-v3/testsuite/30_threads/thread/id/operators.cc new file mode 100644 index 000000000..c8ec7e51d --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/id/operators.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <thread> + +void test01() +{ + // thread::id operators + std::thread::id id1; + std::thread::id id2; + + id1 == id2; + id1 != id2; + id1 < id2; + id1 > id2; + id1 >= id2; + id1 <= id2; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/members/1.cc b/libstdc++-v3/testsuite/30_threads/thread/members/1.cc new file mode 100644 index 000000000..64cdfd9d1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/members/1.cc @@ -0,0 +1,53 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +void f() { } + +int main() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread t(f); + VERIFY( t.joinable() ); + t.join(); + VERIFY( !t.joinable() ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/members/2.cc b/libstdc++-v3/testsuite/30_threads/thread/members/2.cc new file mode 100644 index 000000000..b8e3eb2e0 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/members/2.cc @@ -0,0 +1,53 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +void f() { } + +int main() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread t(f); + VERIFY( t.joinable() ); + t.detach(); + VERIFY( !t.joinable() ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/members/3.cc b/libstdc++-v3/testsuite/30_threads/thread/members/3.cc new file mode 100644 index 000000000..006ccdf4d --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/members/3.cc @@ -0,0 +1,53 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +void f() { } + +int main() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread t(f); + VERIFY( t.get_id() != std::thread::id() ); + t.join(); + VERIFY( t.get_id() == std::thread::id() ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/members/4.cc b/libstdc++-v3/testsuite/30_threads/thread/members/4.cc new file mode 100644 index 000000000..b0b0cfaa8 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/members/4.cc @@ -0,0 +1,48 @@ +// { 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) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +int main() +{ + bool test = false; + + std::thread t; + + try + { + t.join(); + } + catch (const std::system_error&) + { + test = true; + } + + VERIFY( test ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/members/5.cc b/libstdc++-v3/testsuite/30_threads/thread/members/5.cc new file mode 100644 index 000000000..1daaaef88 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/members/5.cc @@ -0,0 +1,48 @@ +// { 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) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <testsuite_hooks.h> + +int main() +{ + bool test = false; + + std::thread t; + + try + { + t.detach(); + } + catch (const std::system_error&) + { + test = true; + } + + VERIFY( test ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/members/hardware_concurrency.cc b/libstdc++-v3/testsuite/30_threads/thread/members/hardware_concurrency.cc new file mode 100644 index 000000000..c2917ca6f --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/members/hardware_concurrency.cc @@ -0,0 +1,36 @@ +// { 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) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <thread> +#include <testsuite_hooks.h> + +int main() +{ + bool test __attribute__((unused)) = true; + + // Current implementation punts on this. + VERIFY( std::thread::hardware_concurrency() == 0 ); + + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/native_handle/cancel.cc b/libstdc++-v3/testsuite/30_threads/thread/native_handle/cancel.cc new file mode 100644 index 000000000..26ff4b42b --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/native_handle/cancel.cc @@ -0,0 +1,45 @@ +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-nanosleep "" } + +// Copyright (C) 2012 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <pthread.h> +#include <thread> +#include <atomic> + +void f(std::atomic<bool>& started) +{ + started = true; + while (true) + std::this_thread::sleep_for(std::chrono::milliseconds(100)); +} + +int main() +{ + std::atomic<bool> started{ false }; + std::thread t(f, std::ref(started)); + while (!started) + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + pthread_cancel(t.native_handle()); + t.join(); +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/native_handle/typesizes.cc b/libstdc++-v3/testsuite/30_threads/thread/native_handle/typesizes.cc new file mode 100644 index 000000000..ffc0e40f6 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/native_handle/typesizes.cc @@ -0,0 +1,33 @@ +// { dg-do run { target *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options " -std=gnu++0x -pthread" { target *-*-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) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <thread> +#include <thread/all.h> + +int main() +{ + typedef std::thread test_type; + __gnu_test::compare_type_to_native_type<test_type>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/30_threads/thread/swap/1.cc b/libstdc++-v3/testsuite/30_threads/thread/swap/1.cc new file mode 100644 index 000000000..2a820ad07 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/swap/1.cc @@ -0,0 +1,93 @@ +// { 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, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <thread> +#include <system_error> +#include <bits/move.h> // std::move +#include <testsuite_hooks.h> + +void f() { } + +void test01() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread t1(f); + std::thread::id t1_id = t1.get_id(); + + std::thread t2; + + t2.swap(t1); + VERIFY( t1.get_id() == std::thread::id() ); + VERIFY( t2.get_id() == t1_id ); + + t2.join(); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + try + { + std::thread t1(f); + std::thread::id t1_id = t1.get_id(); + + std::thread t2; + + std::swap(t1, t2); + VERIFY( t1.get_id() == std::thread::id() ); + VERIFY( t2.get_id() == t1_id ); + + t2.join(); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + test02(); + + return 0; +} |