|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52596 - in sandbox/task: boost/task boost/task/detail libs/task/src
From: oliver.kowalke_at_[hidden]
Date: 2009-04-25 18:10:29
Author: olli
Date: 2009-04-25 18:10:28 EDT (Sat, 25 Apr 2009)
New Revision: 52596
URL: http://svn.boost.org/trac/boost/changeset/52596
Log:
* by async_thread() created thread gets joined correctly by async_handle
Text files modified:
sandbox/task/boost/task/async.hpp | 6 ++++--
sandbox/task/boost/task/detail/interrupter.hpp | 7 +++----
sandbox/task/boost/task/detail/thread_callable.hpp | 28 +++++-----------------------
sandbox/task/libs/task/src/interrupter.cpp | 16 ++++++----------
sandbox/task/libs/task/src/thread_callable.cpp | 4 ----
5 files changed, 18 insertions(+), 43 deletions(-)
Modified: sandbox/task/boost/task/async.hpp
==============================================================================
--- sandbox/task/boost/task/async.hpp (original)
+++ sandbox/task/boost/task/async.hpp 2009-04-25 18:10:28 EDT (Sat, 25 Apr 2009)
@@ -58,7 +58,9 @@
{
void operator()( thread * thrd)
{
+printf("thrd->join() - 1\n");
thrd->join();
+printf("thrd->join() - 2\n");
delete thrd;
}
};
@@ -68,10 +70,10 @@
async_handle< R > async_thread( task< R > t)
{
detail::interrupter intr;
- detail::thread_callable ca( t, intr);
+ detail::thread_callable ca( t);
shared_ptr< thread > thrd( new thread( ca), detail::joiner() );
- ca.set( thrd);
+ intr.set( thrd);
return async_handle< R >( t.get_id(), t.get_future(), intr);
}
Modified: sandbox/task/boost/task/detail/interrupter.hpp
==============================================================================
--- sandbox/task/boost/task/detail/interrupter.hpp (original)
+++ sandbox/task/boost/task/detail/interrupter.hpp 2009-04-25 18:10:28 EDT (Sat, 25 Apr 2009)
@@ -14,7 +14,6 @@
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/utility.hpp>
-#include <boost/weak_ptr.hpp>
#include <boost/task/detail/config.hpp>
@@ -34,14 +33,14 @@
bool done_;
condition_variable cond_;
mutex mtx_;
- weak_ptr< thread > thrd_;
+ shared_ptr< thread > thrd_;
void interrupt_();
public:
impl();
- void set( weak_ptr< thread > const& thrd);
+ void set( shared_ptr< thread > const& thrd);
void reset();
@@ -67,7 +66,7 @@
public:
interrupter();
- void set( weak_ptr< thread > const& thrd);
+ void set( shared_ptr< thread > const& thrd);
void reset();
Modified: sandbox/task/boost/task/detail/thread_callable.hpp
==============================================================================
--- sandbox/task/boost/task/detail/thread_callable.hpp (original)
+++ sandbox/task/boost/task/detail/thread_callable.hpp 2009-04-25 18:10:28 EDT (Sat, 25 Apr 2009)
@@ -29,7 +29,6 @@
{
virtual ~impl() {}
virtual void run() = 0;
- virtual void set( shared_ptr< thread > &) = 0;
};
template< typename R >
@@ -37,42 +36,25 @@
{
private:
task< R > t_;
- detail::interrupter i_;
- semaphore sem_;
public:
- impl_wrapper(
- task< R > const& t,
- detail::interrupter const& i)
- : t_( t), i_( i), sem_( 0)
+ impl_wrapper( task< R > const& t)
+ : t_( t)
{}
void run()
- {
- sem_.wait();
- t_();
- }
-
- void set( shared_ptr< thread > & thrd)
- {
- i_.set( thrd);
- sem_.post();
- }
+ { t_(); }
};
shared_ptr< impl > impl_;
public:
template< typename R >
- thread_callable(
- task< R > const& t,
- detail::interrupter const& i)
- : impl_( new impl_wrapper< R >( t, i) )
+ thread_callable( task< R > const& t)
+ : impl_( new impl_wrapper< R >( t) )
{}
void operator()();
-
- void set( shared_ptr< thread > &);
};
} } }
Modified: sandbox/task/libs/task/src/interrupter.cpp
==============================================================================
--- sandbox/task/libs/task/src/interrupter.cpp (original)
+++ sandbox/task/libs/task/src/interrupter.cpp 2009-04-25 18:10:28 EDT (Sat, 25 Apr 2009)
@@ -18,8 +18,7 @@
if ( ! interruption_requested_ && ! done_)
{
interruption_requested_ = true;
- shared_ptr< thread > tmp( thrd_.lock() );
- if ( tmp) tmp->interrupt();
+ if ( thrd_) thrd_->interrupt();
}
}
@@ -33,16 +32,13 @@
{}
void
-interrupter::impl::set( weak_ptr< thread > const& thrd)
+interrupter::impl::set( shared_ptr< thread > const& thrd)
{
unique_lock< mutex > lk( mtx_);
thrd_ = thrd;
- BOOST_ASSERT( ! thrd_.expired() );
+ BOOST_ASSERT( thrd_);
if ( interruption_requested_)
- {
- shared_ptr< thread > tmp( thrd_.lock() );
- if ( tmp) tmp->interrupt();
- }
+ if ( thrd_) thrd_->interrupt();
}
void
@@ -50,7 +46,7 @@
{
unique_lock< mutex > lk( mtx_);
thrd_.reset();
- BOOST_ASSERT( ! thrd_.expired() );
+ BOOST_ASSERT( thrd_);
try
{ this_thread::interruption_point(); }
catch ( thread_interrupted const&)
@@ -97,7 +93,7 @@
{}
void
-interrupter::set( weak_ptr< thread > const& thrd)
+interrupter::set( shared_ptr< thread > const& thrd)
{ impl_->set( thrd); }
void
Modified: sandbox/task/libs/task/src/thread_callable.cpp
==============================================================================
--- sandbox/task/libs/task/src/thread_callable.cpp (original)
+++ sandbox/task/libs/task/src/thread_callable.cpp 2009-04-25 18:10:28 EDT (Sat, 25 Apr 2009)
@@ -16,9 +16,5 @@
impl_->run();
impl_.reset();
}
-
-void
-thread_callable::set( shared_ptr< thread > & thrd)
-{ impl_->set( thrd); }
} } }
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