diff options
author | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-02-13 00:25:16 +0000 |
---|---|---|
committer | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-02-13 00:25:16 +0000 |
commit | 593c288c881d3f8094e4306bc57cb89ea12a1632 (patch) | |
tree | be2c80ca810b2989aec64480acf5b7a3ea77597e /libstdc++-v3 | |
parent | bfe3dcb6e6d307ff18dc1234828391c0d91497c1 (diff) | |
download | gcc-593c288c881d3f8094e4306bc57cb89ea12a1632.tar.gz |
2009-02-12 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/util/thread/all.h (compare_type_to_native_type_sizes): To...
(compare_type_to_native_type): ...this, add alignment check.
* testsuite/30_threads/condition_variable_any/native_handle/
typesizes.cc: Modify as above.
* testsuite/30_threads/mutex/native_handle/typesizes.cc: Same.
* testsuite/30_threads/timed_mutex/native_handle/typesizes.cc: Same.
* testsuite/30_threads/thread/native_handle/typesizes.cc: Same.
* testsuite/30_threads/recursive_mutex/native_handle/typesizes.cc: Same.
* testsuite/30_threads/condition_variable/native_handle/
typesizes.cc: Same.
* testsuite/30_threads/recursive_timed_mutex/native_handle/
typesizes.cc: Same.
* testsuite/30_threads/thread/cons/1.cc: Add comments.
* testsuite/30_threads/thread/cons/2.cc: Same.
* testsuite/30_threads/thread/cons/3.cc: Same.
* testsuite/30_threads/thread/cons/4.cc: Same.
* testsuite/30_threads/thread/cons/5.cc: Same.
* testsuite/30_threads/thread/cons/6.cc: Same.
* testsuite/30_threads/thread/cons/7.cc: Same.
* testsuite/30_threads/thread/cons/8.cc: Same.
* testsuite/30_threads/thread/cons/9.cc: New.
* testsuite/30_threads/thread/cons/moveable.cc: New.
* src/condition_variable.cc: Clean up whitespace.
* include/std/condition_variable: Same.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@144147 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/testsuite/30_threads/thread/cons/9.cc | 92 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc | 88 |
2 files changed, 180 insertions, 0 deletions
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 00000000000..e93b19a5d08 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/9.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) 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 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 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/moveable.cc b/libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc new file mode 100644 index 00000000000..970931d5dbc --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/moveable.cc @@ -0,0 +1,88 @@ +// { 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 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 <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; +} |