From 8b6ded8d4ff7292cc0c4d9c24a6670d97755aaeb Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Sun, 18 Jan 2009 12:38:10 +0000 Subject: [PATCH] thread (__thread_data_base::__run): Make non-const. * include/std/thread (__thread_data_base::__run): Make non-const. * testsuite/30_threads/thread/cons/5.cc: New. From-SVN: r143483 --- libstdc++-v3/ChangeLog | 5 ++ libstdc++-v3/include/std/thread | 4 +- .../testsuite/30_threads/thread/cons/5.cc | 87 +++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/30_threads/thread/cons/5.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 30287e8480d7..786a1e3c9074 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2009-01-18 Jonathan Wakely + + * include/std/thread (__thread_data_base::__run): Make non-const. + * testsuite/30_threads/thread/cons/5.cc: New. + 2009-01-16 Benjamin Kosnik * src/Makefile.am (sources): Add math_stubs_float.cc. diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread index 422e36265395..00fb018989f8 100644 --- a/libstdc++-v3/include/std/thread +++ b/libstdc++-v3/include/std/thread @@ -65,7 +65,7 @@ namespace std __thread_data_base() = default; virtual ~__thread_data_base() = default; - virtual void __run() const = 0; + virtual void __run() = 0; __gthread_t _M_thread_handle; __thread_data_ptr _M_this_ptr; @@ -80,7 +80,7 @@ namespace std : _M_func(std::forward<_Callable>(__f)) { } - void __run() const + void __run() { _M_func(); } private: 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 000000000000..35ea25abeb10 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/thread/cons/5.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) 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 // std::unary_function +#include // std::ref +#include +#include +#include + +struct nonconst : public std::unary_function +{ + 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; +} -- 2.39.5