|
Boost-Commit : |
From: anthony_at_[hidden]
Date: 2007-11-14 06:08:09
Author: anthonyw
Date: 2007-11-14 06:08:09 EST (Wed, 14 Nov 2007)
New Revision: 41083
URL: http://svn.boost.org/trac/boost/changeset/41083
Log:
ignore and join all threads in group on exception
Text files modified:
trunk/libs/thread/test/test_barrier.cpp | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
Modified: trunk/libs/thread/test/test_barrier.cpp
==============================================================================
--- trunk/libs/thread/test/test_barrier.cpp (original)
+++ trunk/libs/thread/test/test_barrier.cpp 2007-11-14 06:08:09 EST (Wed, 14 Nov 2007)
@@ -10,6 +10,7 @@
#include <boost/thread/barrier.hpp>
#include <boost/test/unit_test.hpp>
+#include <vector>
namespace {
@@ -38,9 +39,24 @@
boost::thread_group g;
global_parameter = 0;
- for (int i = 0; i < N_THREADS; ++i)
- g.create_thread(&barrier_thread);
-
+ std::vector<boost::thread*> threads;
+ threads.reserve(N_THREADS);
+
+ try
+ {
+ for (int i = 0; i < N_THREADS; ++i)
+ threads.push_back(g.create_thread(&barrier_thread));
+ }
+ catch(...)
+ {
+ for(unsigned i=0;i<threads.size();++i)
+ {
+ threads[i]->interrupt();
+ }
+ g.join_all();
+ throw;
+ }
+
g.join_all();
BOOST_CHECK(global_parameter == 5);
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