Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57169 - in trunk/boost/thread: . detail pthread
From: anthony_at_[hidden]
Date: 2009-10-27 05:45:54


Author: anthonyw
Date: 2009-10-27 05:45:53 EDT (Tue, 27 Oct 2009)
New Revision: 57169
URL: http://svn.boost.org/trac/boost/changeset/57169

Log:
Fix for bug #2067 --- use shared_mutex for thread_group rather than a simple mutex
Added:
   trunk/boost/thread/detail/thread_group.hpp (contents, props changed)
   trunk/boost/thread/detail/thread_interruption.hpp (contents, props changed)
Text files modified:
   trunk/boost/thread/detail/thread.hpp | 98 ----------------------------------------
   trunk/boost/thread/pthread/shared_mutex.hpp | 2
   trunk/boost/thread/thread.hpp | 2
   3 files changed, 3 insertions(+), 99 deletions(-)

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2009-10-27 05:45:53 EDT (Tue, 27 Oct 2009)
@@ -357,27 +357,6 @@
 
     namespace this_thread
     {
- class BOOST_THREAD_DECL disable_interruption
- {
- disable_interruption(const disable_interruption&);
- disable_interruption& operator=(const disable_interruption&);
-
- bool interruption_was_enabled;
- friend class restore_interruption;
- public:
- disable_interruption();
- ~disable_interruption();
- };
-
- class BOOST_THREAD_DECL restore_interruption
- {
- restore_interruption(const restore_interruption&);
- restore_interruption& operator=(const restore_interruption&);
- public:
- explicit restore_interruption(disable_interruption& d);
- ~restore_interruption();
- };
-
         thread::id BOOST_THREAD_DECL get_id();
 
         void BOOST_THREAD_DECL interruption_point();
@@ -497,83 +476,6 @@
             detail::add_thread_exit_function(thread_exit_func);
         }
     }
-
- class thread_group:
- private noncopyable
- {
- public:
- ~thread_group()
- {
- for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
- it!=end;
- ++it)
- {
- delete *it;
- }
- }
-
- template<typename F>
- thread* create_thread(F threadfunc)
- {
- boost::lock_guard<mutex> guard(m);
- std::auto_ptr<thread> new_thread(new thread(threadfunc));
- threads.push_back(new_thread.get());
- return new_thread.release();
- }
-
- void add_thread(thread* thrd)
- {
- if(thrd)
- {
- boost::lock_guard<mutex> guard(m);
- threads.push_back(thrd);
- }
- }
-
- void remove_thread(thread* thrd)
- {
- boost::lock_guard<mutex> guard(m);
- std::list<thread*>::iterator const it=std::find(threads.begin(),threads.end(),thrd);
- if(it!=threads.end())
- {
- threads.erase(it);
- }
- }
-
- void join_all()
- {
- boost::lock_guard<mutex> guard(m);
-
- for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
- it!=end;
- ++it)
- {
- (*it)->join();
- }
- }
-
- void interrupt_all()
- {
- boost::lock_guard<mutex> guard(m);
-
- for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
- it!=end;
- ++it)
- {
- (*it)->interrupt();
- }
- }
-
- size_t size() const
- {
- boost::lock_guard<mutex> guard(m);
- return threads.size();
- }
-
- private:
- std::list<thread*> threads;
- mutable mutex m;
- };
 }
 
 #ifdef BOOST_MSVC

Added: trunk/boost/thread/detail/thread_group.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/detail/thread_group.hpp 2009-10-27 05:45:53 EDT (Tue, 27 Oct 2009)
@@ -0,0 +1,105 @@
+#ifndef BOOST_THREAD_DETAIL_THREAD_GROUP_HPP
+#define BOOST_THREAD_DETAIL_THREAD_GROUP_HPP
+// 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)
+// (C) Copyright 2007-9 Anthony Williams
+
+#include <list>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/mutex.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+#ifdef BOOST_MSVC
+#pragma warning(push)
+#pragma warning(disable:4251)
+#endif
+
+namespace boost
+{
+ class thread_group:
+ private noncopyable
+ {
+ public:
+ ~thread_group()
+ {
+ for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
+ it!=end;
+ ++it)
+ {
+ delete *it;
+ }
+ }
+
+ template<typename F>
+ thread* create_thread(F threadfunc)
+ {
+ boost::lock_guard<shared_mutex> guard(m);
+ std::auto_ptr<thread> new_thread(new thread(threadfunc));
+ threads.push_back(new_thread.get());
+ return new_thread.release();
+ }
+
+ void add_thread(thread* thrd)
+ {
+ if(thrd)
+ {
+ boost::lock_guard<shared_mutex> guard(m);
+ threads.push_back(thrd);
+ }
+ }
+
+ void remove_thread(thread* thrd)
+ {
+ boost::lock_guard<shared_mutex> guard(m);
+ std::list<thread*>::iterator const it=std::find(threads.begin(),threads.end(),thrd);
+ if(it!=threads.end())
+ {
+ threads.erase(it);
+ }
+ }
+
+ void join_all()
+ {
+ boost::shared_lock<shared_mutex> guard(m);
+
+ for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
+ it!=end;
+ ++it)
+ {
+ (*it)->join();
+ }
+ }
+
+ void interrupt_all()
+ {
+ boost::shared_lock<shared_mutex> guard(m);
+
+ for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
+ it!=end;
+ ++it)
+ {
+ (*it)->interrupt();
+ }
+ }
+
+ size_t size() const
+ {
+ boost::shared_lock<shared_mutex> guard(m);
+ return threads.size();
+ }
+
+ private:
+ std::list<thread*> threads;
+ mutable shared_mutex m;
+ };
+}
+
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif

Added: trunk/boost/thread/detail/thread_interruption.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/detail/thread_interruption.hpp 2009-10-27 05:45:53 EDT (Tue, 27 Oct 2009)
@@ -0,0 +1,35 @@
+#ifndef BOOST_THREAD_DETAIL_THREAD_INTERRUPTION_HPP
+#define BOOST_THREAD_DETAIL_THREAD_INTERRUPTION_HPP
+// 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)
+// (C) Copyright 2007-9 Anthony Williams
+
+namespace boost
+{
+ namespace this_thread
+ {
+ class BOOST_THREAD_DECL disable_interruption
+ {
+ disable_interruption(const disable_interruption&);
+ disable_interruption& operator=(const disable_interruption&);
+
+ bool interruption_was_enabled;
+ friend class restore_interruption;
+ public:
+ disable_interruption();
+ ~disable_interruption();
+ };
+
+ class BOOST_THREAD_DECL restore_interruption
+ {
+ restore_interruption(const restore_interruption&);
+ restore_interruption& operator=(const restore_interruption&);
+ public:
+ explicit restore_interruption(disable_interruption& d);
+ ~restore_interruption();
+ };
+ }
+}
+
+#endif

Modified: trunk/boost/thread/pthread/shared_mutex.hpp
==============================================================================
--- trunk/boost/thread/pthread/shared_mutex.hpp (original)
+++ trunk/boost/thread/pthread/shared_mutex.hpp 2009-10-27 05:45:53 EDT (Tue, 27 Oct 2009)
@@ -10,8 +10,8 @@
 #include <boost/assert.hpp>
 #include <boost/static_assert.hpp>
 #include <boost/thread/mutex.hpp>
-#include <boost/thread/thread.hpp>
 #include <boost/thread/condition_variable.hpp>
+#include <boost/thread/detail/thread_interruption.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 

Modified: trunk/boost/thread/thread.hpp
==============================================================================
--- trunk/boost/thread/thread.hpp (original)
+++ trunk/boost/thread/thread.hpp 2009-10-27 05:45:53 EDT (Tue, 27 Oct 2009)
@@ -20,6 +20,8 @@
 #endif
 
 #include <boost/thread/detail/thread.hpp>
+#include <boost/thread/detail/thread_interruption.hpp>
+#include <boost/thread/detail/thread_group.hpp>
 
 
 #endif


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