Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-06-05 07:16:05


Author: anthonyw
Date: 2008-06-05 07:16:05 EDT (Thu, 05 Jun 2008)
New Revision: 46161
URL: http://svn.boost.org/trac/boost/changeset/46161

Log:
Test and fix for bug #1958 on Win32
Text files modified:
   trunk/boost/thread/win32/tss.hpp | 10 +++++--
   trunk/libs/thread/test/test_tss.cpp | 48 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 55 insertions(+), 3 deletions(-)

Modified: trunk/boost/thread/win32/tss.hpp
==============================================================================
--- trunk/boost/thread/win32/tss.hpp (original)
+++ trunk/boost/thread/win32/tss.hpp 2008-06-05 07:16:05 EDT (Thu, 05 Jun 2008)
@@ -64,9 +64,13 @@
         thread_specific_ptr():
             cleanup(detail::heap_new<delete_data>(),detail::do_heap_delete<delete_data>())
         {}
- explicit thread_specific_ptr(void (*func_)(T*)):
- cleanup(detail::heap_new<run_custom_cleanup_function>(func_),detail::do_heap_delete<run_custom_cleanup_function>())
- {}
+ explicit thread_specific_ptr(void (*func_)(T*))
+ {
+ if(func_)
+ {
+ cleanup.reset(detail::heap_new<run_custom_cleanup_function>(func_),detail::do_heap_delete<run_custom_cleanup_function>());
+ }
+ }
         ~thread_specific_ptr()
         {
             reset();

Modified: trunk/libs/thread/test/test_tss.cpp
==============================================================================
--- trunk/libs/thread/test/test_tss.cpp (original)
+++ trunk/libs/thread/test/test_tss.cpp 2008-06-05 07:16:05 EDT (Thu, 05 Jun 2008)
@@ -258,11 +258,58 @@
     }
 }
 
+struct dummy_class_tracks_deletions
+{
+ static unsigned deletions;
+
+ ~dummy_class_tracks_deletions()
+ {
+ ++deletions;
+ }
+
+};
+
+unsigned dummy_class_tracks_deletions::deletions=0;
+
+boost::thread_specific_ptr<dummy_class_tracks_deletions> tss_with_null_cleanup(NULL);
+
+void tss_thread_with_null_cleanup(dummy_class_tracks_deletions* delete_tracker)
+{
+ tss_with_null_cleanup.reset(delete_tracker);
+}
+
+void do_test_tss_does_no_cleanup_with_null_cleanup_function()
+{
+ dummy_class_tracks_deletions* delete_tracker=new dummy_class_tracks_deletions;
+ boost::thread t(tss_thread_with_null_cleanup,delete_tracker);
+ try
+ {
+ t.join();
+ }
+ catch(...)
+ {
+ t.interrupt();
+ t.join();
+ throw;
+ }
+
+ BOOST_CHECK(!dummy_class_tracks_deletions::deletions);
+ if(!dummy_class_tracks_deletions::deletions)
+ {
+ delete delete_tracker;
+ }
+}
+
 void test_tss_does_no_cleanup_after_release()
 {
     timed_test(&do_test_tss_does_no_cleanup_after_release, 2);
 }
 
+void test_tss_does_no_cleanup_with_null_cleanup_function()
+{
+ timed_test(&do_test_tss_does_no_cleanup_with_null_cleanup_function, 2);
+}
+
 boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
 {
     boost::unit_test_framework::test_suite* test =
@@ -271,6 +318,7 @@
     test->add(BOOST_TEST_CASE(test_tss));
     test->add(BOOST_TEST_CASE(test_tss_with_custom_cleanup));
     test->add(BOOST_TEST_CASE(test_tss_does_no_cleanup_after_release));
+ test->add(BOOST_TEST_CASE(test_tss_does_no_cleanup_with_null_cleanup_function));
 
     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