Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57925 - in trunk: boost/thread/detail libs/thread/test
From: anthony_at_[hidden]
Date: 2009-11-25 06:05:55


Author: anthonyw
Date: 2009-11-25 06:05:55 EST (Wed, 25 Nov 2009)
New Revision: 57925
URL: http://svn.boost.org/trac/boost/changeset/57925

Log:
Added test and fix for issue 2742
Added:
   trunk/libs/thread/test/test_thread_exit.cpp (contents, props changed)
Text files modified:
   trunk/boost/thread/detail/thread.hpp | 4 ++--
   trunk/libs/thread/test/Jamfile.v2 | 1 +
   2 files changed, 3 insertions(+), 2 deletions(-)

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2009-11-25 06:05:55 EST (Wed, 25 Nov 2009)
@@ -445,7 +445,7 @@
         {
             virtual ~thread_exit_function_base()
             {}
- virtual void operator()() const=0;
+ virtual void operator()()=0;
         };
         
         template<typename F>
@@ -458,7 +458,7 @@
                 f(f_)
             {}
             
- void operator()() const
+ void operator()()
             {
                 f();
             }

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2009-11-25 06:05:55 EST (Wed, 25 Nov 2009)
@@ -42,6 +42,7 @@
           [ thread-run test_thread_move_return.cpp ]
           [ thread-run test_thread_launching.cpp ]
           [ thread-run test_thread_mf.cpp ]
+ [ thread-run test_thread_exit.cpp ]
           [ thread-run test_move_function.cpp ]
           [ thread-run test_mutex.cpp ]
           [ thread-run test_condition_notify_one.cpp ]

Added: trunk/libs/thread/test/test_thread_exit.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/test_thread_exit.cpp 2009-11-25 06:05:55 EST (Wed, 25 Nov 2009)
@@ -0,0 +1,73 @@
+// (C) Copyright 2009 Anthony Williams
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/thread/thread.hpp"
+#include "boost/thread/mutex.hpp"
+#include "boost/thread/condition.hpp"
+#include "boost/thread/future.hpp"
+#include <utility>
+#include <memory>
+#include <string>
+
+#include <boost/test/unit_test.hpp>
+
+boost::thread::id exit_func_thread_id;
+
+void exit_func()
+{
+ exit_func_thread_id=boost::this_thread::get_id();
+}
+
+void tf1()
+{
+ boost::this_thread::at_thread_exit(exit_func);
+ BOOST_CHECK(exit_func_thread_id!=boost::this_thread::get_id());
+}
+
+void test_thread_exit_func_runs_when_thread_exits()
+{
+ exit_func_thread_id=boost::thread::id();
+ boost::thread t(tf1);
+ boost::thread::id const t_id=t.get_id();
+ t.join();
+ BOOST_CHECK(exit_func_thread_id==t_id);
+}
+
+struct fo
+{
+ void operator()()
+ {
+ exit_func_thread_id=boost::this_thread::get_id();
+ }
+};
+
+void tf2()
+{
+ boost::this_thread::at_thread_exit(fo());
+ BOOST_CHECK(exit_func_thread_id!=boost::this_thread::get_id());
+}
+
+
+void test_can_use_function_object_for_exit_func()
+{
+ exit_func_thread_id=boost::thread::id();
+ boost::thread t(tf2);
+ boost::thread::id const t_id=t.get_id();
+ t.join();
+ BOOST_CHECK(exit_func_thread_id==t_id);
+}
+
+
+boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
+{
+ boost::unit_test_framework::test_suite* test =
+ BOOST_TEST_SUITE("Boost.Threads: futures test suite");
+
+ test->add(BOOST_TEST_CASE(test_thread_exit_func_runs_when_thread_exits));
+ test->add(BOOST_TEST_CASE(test_can_use_function_object_for_exit_func));
+
+ return test;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk