]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
thread (__thread_data_base::__run): Make non-const.
authorJonathan Wakely <jwakely.gcc@gmail.com>
Sun, 18 Jan 2009 12:38:10 +0000 (12:38 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Sun, 18 Jan 2009 12:38:10 +0000 (12:38 +0000)
* include/std/thread (__thread_data_base::__run): Make non-const.
* testsuite/30_threads/thread/cons/5.cc: New.

From-SVN: r143483

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/thread
libstdc++-v3/testsuite/30_threads/thread/cons/5.cc [new file with mode: 0644]

index 30287e8480d7bfbc635c2ecaf174a9aef413e82b..786a1e3c90747c7f743f40a0d95c6df034951125 100644 (file)
@@ -1,3 +1,8 @@
+2009-01-18  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       * include/std/thread (__thread_data_base::__run): Make non-const.
+       * testsuite/30_threads/thread/cons/5.cc: New.
+
 2009-01-16  Benjamin Kosnik  <bkoz@redhat.com>
 
        * src/Makefile.am (sources): Add math_stubs_float.cc.
index 422e36265395168f81b2d0150017d7f33b765780..00fb018989f83882934798c85fb3de5ae87f69fe 100644 (file)
@@ -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 (file)
index 0000000..35ea25a
--- /dev/null
@@ -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 <functional> // std::unary_function
+#include <utility> // 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;
+}