From b47f0044ab61a5995966a5af9d65da24d4490627 Mon Sep 17 00:00:00 2001 From: Chris Fairles Date: Mon, 9 Feb 2009 00:13:47 +0000 Subject: [PATCH] thread (thread<>::thread(_Callable)): Explicitly use _Callable as template argument for _M_make_shared_data. 2009-02-08 Chris Fairles * include/std/thread (thread<>::thread(_Callable)): Explicitly use _Callable as template argument for _M_make_shared_data. * testsuite/30_threads/thread/cons/6.cc: New. * testsuite/30_threads/thread/cons/7.cc: New. * testsuite/30_threads/thread/cons/8.cc: New. From-SVN: r144023 --- libstdc++-v3/ChangeLog | 8 ++ libstdc++-v3/include/std/thread | 2 +- .../testsuite/30_threads/thread/cons/6.cc | 70 ++++++++++++++++ .../testsuite/30_threads/thread/cons/7.cc | 80 +++++++++++++++++++ .../testsuite/30_threads/thread/cons/8.cc | 80 +++++++++++++++++++ 5 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/30_threads/thread/cons/6.cc create mode 100644 libstdc++-v3/testsuite/30_threads/thread/cons/7.cc create mode 100644 libstdc++-v3/testsuite/30_threads/thread/cons/8.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8c1ceb8a173..d80ab82a17a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2009-02-08 Chris Fairles + + * include/std/thread (thread<>::thread(_Callable)): Explicitly use + _Callable as template argument for _M_make_shared_data. + * testsuite/30_threads/thread/cons/6.cc: New. + * testsuite/30_threads/thread/cons/7.cc: New. + * testsuite/30_threads/thread/cons/8.cc: New. + 2009-02-07 Benjamin Kosnik * testsuite/30_threads/thread/member: To.. diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread index 9ce5fdd584c..3704192913f 100644 --- a/libstdc++-v3/include/std/thread +++ b/libstdc++-v3/include/std/thread @@ -128,7 +128,7 @@ namespace std template explicit thread(_Callable __f) - : _M_data(_M_make_shared_data(__f)) + : _M_data(_M_make_shared_data<_Callable>(__f)) { _M_start_thread(); } template 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 00000000000..0a6d7470fa9 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/6.cc @@ -0,0 +1,70 @@ +// { 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 +#include +#include + +bool f_was_called = false; + +void f() +{ + f_was_called = true; +} + +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 00000000000..fafa72ac277 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/7.cc @@ -0,0 +1,80 @@ +// { 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 +#include +#include + +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; + } +}; + +void test07() +{ + bool test __attribute__((unused)) = true; + + try + { + copyable c; + copyable& rc = c; + std::thread t1(rc); + t1.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 00000000000..8c6b2e1f921 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/8.cc @@ -0,0 +1,80 @@ +// { 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 +#include +#include + +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; + } +}; + +void test08() +{ + bool test __attribute__((unused)) = true; + + try + { + moveable m; + std::thread t1(std::move(m)); + t1.join(); + VERIFY( functor_was_called ); + } + catch (const std::system_error&) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test08(); + return 0; +}