Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58583 - in sandbox/task: boost/task boost/task/detail boost/task/spin libs/task/examples libs/task/examples/sync libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2009-12-30 07:14:31


Author: olli
Date: 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
New Revision: 58583
URL: http://svn.boost.org/trac/boost/changeset/58583

Log:
- spin::shared_future used inside task

Text files modified:
   sandbox/task/boost/task/as_sub_task.hpp | 11 ++---
   sandbox/task/boost/task/callable.hpp | 46 ++++---------------------
   sandbox/task/boost/task/detail/pool_base.hpp | 15 +++-----
   sandbox/task/boost/task/detail/worker.hpp | 35 ++++---------------
   sandbox/task/boost/task/handle.hpp | 55 ++++++++++++-----------------
   sandbox/task/boost/task/new_thread.hpp | 7 +--
   sandbox/task/boost/task/own_thread.hpp | 8 +--
   sandbox/task/boost/task/spin/future.hpp | 45 +++++++++++++++++++++++++
   sandbox/task/boost/task/task.hpp | 11 +++--
   sandbox/task/libs/task/examples/bind_to_processors.cpp | 2
   sandbox/task/libs/task/examples/interrupt.cpp | 2
   sandbox/task/libs/task/examples/priority.cpp | 2
   sandbox/task/libs/task/examples/shutdown_now.cpp | 2
   sandbox/task/libs/task/examples/smart.cpp | 2
   sandbox/task/libs/task/examples/sub_tasks.cpp | 72 ++++++++++++++++-----------------------
   sandbox/task/libs/task/examples/submit.cpp | 2
   sandbox/task/libs/task/examples/sync/fork_join_event.cpp | 2
   sandbox/task/libs/task/examples/sync/message_passing.cpp | 2
   sandbox/task/libs/task/examples/sync/ping_pong.cpp | 2
   sandbox/task/libs/task/test/Jamfile.v2 | 2
   20 files changed, 146 insertions(+), 179 deletions(-)

Modified: sandbox/task/boost/task/as_sub_task.hpp
==============================================================================
--- sandbox/task/boost/task/as_sub_task.hpp (original)
+++ sandbox/task/boost/task/as_sub_task.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -10,7 +10,6 @@
 #include <boost/bind.hpp>
 #include <boost/config.hpp>
 #include <boost/move/move.hpp>
-#include <boost/shared_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 
 #include <boost/task/callable.hpp>
@@ -29,22 +28,20 @@
 struct as_sub_task
 {
         template< typename R >
- handle< R > operator()( BOOST_RV_REF( task< R >) t_)
+ handle< R > operator()( BOOST_RV_REF( task< R >) t)
         {
                 detail::worker * w( detail::worker::tss_get() );
                 if ( w)
                 {
- spin::packaged_task< R > t( t_.task_.fn_);
- shared_ptr< spin::shared_future< R > > f(
- new spin::shared_future< R >(
- t.get_future() ) );
+ spin::shared_future< R > f(
+ t.get_future() );
                         context ctx;
                         handle< R > h( f, ctx);
                         w->put( callable( t, ctx) );
                         return h;
                 }
                 else
- return new_thread()( t_);
+ return new_thread()( t);
         }
 };
 

Modified: sandbox/task/boost/task/callable.hpp
==============================================================================
--- sandbox/task/boost/task/callable.hpp (original)
+++ sandbox/task/boost/task/callable.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -14,8 +14,6 @@
 
 #include <boost/task/context.hpp>
 #include <boost/task/detail/config.hpp>
-#include <boost/task/spin/future.hpp>
-#include <boost/task/task.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 
@@ -37,37 +35,16 @@
                 virtual void reset( shared_ptr< thread > const&) = 0;
         };
 
- template< typename R >
- class task_wrapper : public impl
+ template< typename T >
+ class wrapper : public impl
         {
         private:
- task< R > t_;
+ T t_;
                 context ctx_;
 
         public:
- task_wrapper(
- BOOST_RV_REF( task< R >) t,
- context const& ctx) :
- t_( t), ctx_( ctx)
- {}
-
- void run()
- { t_(); }
-
- void reset( shared_ptr< thread > const& thrd)
- { ctx_.reset( thrd); }
- };
-
- template< typename R >
- class packaged_task_wrapper : public impl
- {
- private:
- spin::packaged_task< R > t_;
- context ctx_;
-
- public:
- packaged_task_wrapper(
- BOOST_RV_REF( spin::packaged_task< R >) t,
+ wrapper(
+ BOOST_RV_REF( T) t,
                                 context const& ctx) :
                         t_( t), ctx_( ctx)
                 {}
@@ -84,18 +61,11 @@
 public:
         callable();
 
- template< typename R >
- callable(
- BOOST_RV_REF( task< R >) t,
- context const& ctx) :
- impl_( new task_wrapper< R >( t, ctx) )
- {}
-
- template< typename R >
+ template< typename T >
         callable(
- BOOST_RV_REF( spin::packaged_task< R >) t,
+ BOOST_RV_REF( T) t,
                         context const& ctx) :
- impl_( new packaged_task_wrapper< R >( t, ctx) )
+ impl_( new wrapper< T >( t, ctx) )
         {}
 
         void operator()();

Modified: sandbox/task/boost/task/detail/pool_base.hpp
==============================================================================
--- sandbox/task/boost/task/detail/pool_base.hpp (original)
+++ sandbox/task/boost/task/detail/pool_base.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -29,6 +29,7 @@
 #include <boost/task/handle.hpp>
 #include <boost/task/poolsize.hpp>
 #include <boost/task/scanns.hpp>
+#include <boost/task/spin/future.hpp>
 #include <boost/task/stacksize.hpp>
 #include <boost/task/task.hpp>
 #include <boost/task/watermark.hpp>
@@ -283,9 +284,7 @@
                 if ( deactivated_() )
                         throw task_rejected("pool is closed");
 
- shared_ptr< shared_future< R > > f(
- new shared_future< R >(
- t.get_future() ) );
+ spin::shared_future< R > f( t.get_future() );
                 context ctx;
                 handle< R > h( f, ctx);
                 queue_.put( callable( boost::move( t), ctx) );
@@ -298,15 +297,13 @@
                 if ( deactivated_() )
                         throw task_rejected("pool is closed");
 
- shared_ptr< shared_future< R > > f(
- new shared_future< R >(
- t.get_future() ) );
+ spin::shared_future< R > f( t.get_future() );
                 context ctx;
                 handle< R > h( f, ctx);
                 queue_.put(
- value_type(
- callable( boost::move( t), ctx),
- attr) );
+ value_type(
+ callable( boost::move( t), ctx),
+ attr) );
                 return h;
         }
 };

Modified: sandbox/task/boost/task/detail/worker.hpp
==============================================================================
--- sandbox/task/boost/task/detail/worker.hpp (original)
+++ sandbox/task/boost/task/detail/worker.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -141,13 +141,9 @@
                                  try_steal_other_callable_( ca) ||
                                  try_take_global_callable_( ca) )
                         {
- fprintf(stdout,"run_(): execute_( ca)\n");
                                 execute_( ca);
                                 scns_ = 0;
- if ( 0 < sched_.ready() ){
- fprintf(stdout,"run_(): return because %d fibers are ready\n", sched_.ready() );
- return;
- }
+ if ( 0 < sched_.ready() ) return;
                         }
                         else
                         {
@@ -174,10 +170,8 @@
                                 }
                                 else
                                 {
- if ( 0 < sched_.ready() )
- return;
- else
- this_thread::yield();
+ if ( 0 < sched_.ready() ) return;
+ this_thread::yield();
                                 }
                         }
                 }
@@ -251,30 +245,17 @@
                                         this),
                                 stack_size_);
                 while ( ! shutdown_() )
- {
- fprintf(stdout,"run(): call scheduler::run()\n");
                         sched_.run();
- }
         }
 
         void block()
         {
- if ( 0 == sched_.ready() )
- {
- sched_.make_fiber(
- bind(
- & worker_object::run_,
- this),
- stack_size_);
- fprintf(stdout,"block(): new fiber added to scheduler\n");
- }
- else
- {
- fprintf(stdout,"block(): scheduler has == ready fibers%d\n", sched_.ready() );
- }
- fprintf(stdout,"block(): before this_fiber::yield()\n");
+ sched_.make_fiber(
+ bind(
+ & worker_object::run_,
+ this),
+ stack_size_);
                 this_fiber::yield();
- fprintf(stdout,"block: after this_fiber::yield()\n");
         }
 };
 

Modified: sandbox/task/boost/task/handle.hpp
==============================================================================
--- sandbox/task/boost/task/handle.hpp (original)
+++ sandbox/task/boost/task/handle.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -14,8 +14,8 @@
 #include <boost/utility/enable_if.hpp>
 
 #include <boost/task/context.hpp>
-#include <boost/thread/future.hpp>
 #include <boost/task/exceptions.hpp>
+#include <boost/task/spin/future.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 
@@ -48,16 +48,16 @@
         template< typename T1, typename T2, typename T3, typename T4, typename T5 >
         friend unsigned int waitfor_any( handle< T1 > &, handle< T2 > &, handle< T3 > &, handle< T4 > &, handle< T5 > &);
 
- shared_ptr< shared_future< R > > fut_;
- context ctx_;
+ spin::shared_future< R > fut_;
+ context ctx_;
 
 public:
         handle() :
- fut_( new shared_future< R >() ), ctx_()
+ fut_(), ctx_()
         {}
 
         handle(
- shared_ptr< shared_future< R > > const& fut,
+ spin::shared_future< R > const& fut,
                         context const& ctx) :
                 fut_( fut),
                 ctx_( ctx)
@@ -91,7 +91,7 @@
         R get()
         {
                 try
- { return fut_->get(); }
+ { return fut_.get(); }
                 catch ( future_uninitialized const&)
                 { throw task_uninitialized(); }
                 catch ( broken_promise const&)
@@ -101,31 +101,18 @@
         }
 
         bool is_ready() const
- { return fut_->is_ready(); }
+ { return fut_.is_ready(); }
 
         bool has_value() const
- { return fut_->has_value(); }
+ { return fut_.has_value(); }
 
         bool has_exception() const
- { return fut_->has_exception(); }
+ { return fut_.has_exception(); }
 
         void wait() const
         {
                 try
- { fut_->wait(); }
- catch ( future_uninitialized const&)
- { throw task_uninitialized(); }
- catch ( broken_promise const&)
- { throw broken_task(); }
- catch ( thread_interrupted const&)
- { throw task_interrupted(); }
- }
-
- template< typename TimeDuration >
- bool wait_for( TimeDuration const& rel_time) const
- {
- try
- { return fut_->timed_wait( rel_time); }
+ { fut_.wait(); }
                 catch ( future_uninitialized const&)
                 { throw task_uninitialized(); }
                 catch ( broken_promise const&)
@@ -137,7 +124,7 @@
         bool wait_until( system_time const& abs_time) const
         {
                 try
- { return fut_->timed_wait_until( abs_time); }
+ { return fut_.timed_wait_until( abs_time); }
                 catch ( future_uninitialized const&)
                 { throw task_uninitialized(); }
                 catch ( broken_promise const&)
@@ -146,6 +133,10 @@
                 { throw task_interrupted(); }
         }
 
+ template< typename TimeDuration >
+ bool wait_for( TimeDuration const& rel_time) const
+ { return wait_until( get_system_time() + rel_time); }
+
         void swap( handle< R > & other)
         {
                 fut_.swap( other.fut_);
@@ -179,7 +170,7 @@
 void waitfor_all( handle< T1 > & t1, handle< T2 > & t2)
 {
         try
- { wait_for_all( * t1.fut_, * t2.fut_); }
+ { spin::wait_for_all( t1.fut_, t2.fut_); }
         catch ( thread_interrupted const&)
         { throw task_interrupted(); }
 }
@@ -188,7 +179,7 @@
 void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3)
 {
         try
- { wait_for_all( * t1.fut_, * t2.fut_, * t3.fut_); }
+ { spin::wait_for_all( t1.fut_, t2.fut_, t3.fut_); }
         catch ( thread_interrupted const&)
         { throw task_interrupted(); }
 }
@@ -197,7 +188,7 @@
 void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4)
 {
         try
- { wait_for_all( * t1.fut_, * t2.fut_, * t3.fut_, * t4.fut_); }
+ { spin::wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
         catch ( thread_interrupted const&)
         { throw task_interrupted(); }
 }
@@ -206,7 +197,7 @@
 void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5)
 {
         try
- { wait_for_all( * t1.fut_, * t2.fut_, * t3.fut_, * t4.fut_, * t5.fut_); }
+ { spin::wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
         catch ( thread_interrupted const&)
         { throw task_interrupted(); }
 }
@@ -229,7 +220,7 @@
 typename enable_if< is_handle_type< H1 >, unsigned >::type waitfor_any( H1 & h1, H2 & h2)
 {
         try
- { return wait_for_any( * h1.fut_, * h2.fut_ ); }
+ { return spin::wait_for_any( h1.fut_, h2.fut_ ); }
         catch ( thread_interrupted const&)
         { throw task_interrupted(); }
 }
@@ -238,7 +229,7 @@
 unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3)
 {
         try
- { return wait_for_any( * t1.fut_, * t2.fut_, * t3.fut_ ); }
+ { return spin::wait_for_any( t1.fut_, t2.fut_, t3.fut_ ); }
         catch ( thread_interrupted const&)
         { throw task_interrupted(); }
 }
@@ -247,7 +238,7 @@
 unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4)
 {
         try
- { return wait_for_any( * t1.fut_, * t2.fut_, * t3.fut_, * t4.fut_ ); }
+ { return spin::wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_ ); }
         catch ( thread_interrupted const&)
         { throw task_interrupted(); }
 }
@@ -256,7 +247,7 @@
 unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5)
 {
         try
- { return wait_for_any( * t1.fut_, * t2.fut_, * t3.fut_, * t4.fut_, * t5.fut_ ); }
+ { return spin::wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_ ); }
         catch ( thread_interrupted const&)
         { throw task_interrupted(); }
 }

Modified: sandbox/task/boost/task/new_thread.hpp
==============================================================================
--- sandbox/task/boost/task/new_thread.hpp (original)
+++ sandbox/task/boost/task/new_thread.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -12,11 +12,11 @@
 #include <boost/move/move.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/thread.hpp>
-#include <boost/thread/future.hpp>
 
 #include <boost/task/callable.hpp>
 #include <boost/task/context.hpp>
 #include <boost/task/handle.hpp>
+#include <boost/task/spin/future.hpp>
 #include <boost/task/task.hpp>
 
 #include <boost/config/abi_prefix.hpp>
@@ -65,9 +65,8 @@
         template< typename R >
         handle< R > operator()( BOOST_RV_REF( task< R >) t)
         {
- shared_ptr< shared_future< R > > f(
- new shared_future< R >(
- t.get_future() ) );
+ spin::shared_future< R > f(
+ t.get_future() );
                 context ctx1, ctx2;
                 handle< R > h( f, ctx1);
                 callable ca( t, ctx2);

Modified: sandbox/task/boost/task/own_thread.hpp
==============================================================================
--- sandbox/task/boost/task/own_thread.hpp (original)
+++ sandbox/task/boost/task/own_thread.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -9,12 +9,11 @@
 
 #include <boost/config.hpp>
 #include <boost/move/move.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/thread/future.hpp>
 
 #include <boost/task/callable.hpp>
 #include <boost/task/context.hpp>
 #include <boost/task/handle.hpp>
+#include <boost/task/spin/future.hpp>
 #include <boost/task/task.hpp>
 
 #include <boost/config/abi_prefix.hpp>
@@ -27,9 +26,8 @@
         template< typename R >
         handle< R > operator()( BOOST_RV_REF( task< R >) t)
         {
- shared_ptr< shared_future< R > > f(
- new shared_future< R >(
- t.get_future() ) );
+ spin::shared_future< R > f(
+ t.get_future() );
                 context ctx;
                 handle< R > h( f, ctx);
                 callable ca( t, ctx);

Modified: sandbox/task/boost/task/spin/future.hpp
==============================================================================
--- sandbox/task/boost/task/spin/future.hpp (original)
+++ sandbox/task/boost/task/spin/future.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -119,6 +119,21 @@
             boost::rethrow_exception(exception);
         }
     }
+
+ bool timed_wait_until(boost::system_time const& target_time)
+ {
+ boost::unique_lock<mutex> lock(mtx);
+ do_callback(lock);
+ while(!done)
+ {
+ bool const success=waiters.timed_wait(lock,target_time);
+ if(!success && !done)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
     
     void mark_exceptional_finish_internal(boost::exception_ptr const& e)
     {
@@ -562,6 +577,21 @@
             }
             future->wait(false);
         }
+
+ template<typename Duration>
+ bool timed_wait(Duration const& rel_time) const
+ {
+ return timed_wait_until(boost::get_system_time()+rel_time);
+ }
+
+ bool timed_wait_until(boost::system_time const& abs_time) const
+ {
+ if(!future)
+ {
+ throw future_uninitialized();
+ }
+ return future->timed_wait_until(abs_time);
+ }
 };
 
 template <typename R>
@@ -673,6 +703,21 @@
             }
             future->wait(false);
         }
+
+ template<typename Duration>
+ bool timed_wait(Duration const& rel_time) const
+ {
+ return timed_wait_until(boost::get_system_time()+rel_time);
+ }
+
+ bool timed_wait_until(boost::system_time const& abs_time) const
+ {
+ if(!future)
+ {
+ throw future_uninitialized();
+ }
+ return future->timed_wait_until(abs_time);
+ }
 };
 
 template <typename R>

Modified: sandbox/task/boost/task/task.hpp
==============================================================================
--- sandbox/task/boost/task/task.hpp (original)
+++ sandbox/task/boost/task/task.hpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -16,6 +16,7 @@
 #include <boost/utility/result_of.hpp>
 
 #include <boost/task/exceptions.hpp>
+#include <boost/task/spin/future.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 
@@ -30,7 +31,7 @@
         bool done_;
 
 protected:
- promise< R > prom_;
+ spin::promise< R > prom_;
 
         virtual void do_run() = 0;
 
@@ -48,7 +49,7 @@
                 done_ = true;
         }
 
- unique_future< R > get_future()
+ spin::unique_future< R > get_future()
         { return prom_.get_future(); }
 
         template< typename Cb >
@@ -104,7 +105,7 @@
                 { this->prom_.set_exception( copy_exception( e) ); }
                 catch ( std::bad_exception const& e)
                 { this->prom_.set_exception( copy_exception( e) ); }
- catch(...)
+ catch (...)
                 { this->prom_.set_exception( current_exception() ); }
         }
 
@@ -165,7 +166,7 @@
                 { this->prom_.set_exception( copy_exception( e) ); }
                 catch ( std::bad_exception const& e)
                 { this->prom_.set_exception( copy_exception( e) ); }
- catch(...)
+ catch (...)
                 { this->prom_.set_exception( current_exception() ); }
         }
 
@@ -242,7 +243,7 @@
                 task_->run();
         }
 
- unique_future< R > get_future()
+ spin::unique_future< R > get_future()
         {
                 if ( ! task_)
                         throw task_moved();

Modified: sandbox/task/libs/task/examples/bind_to_processors.cpp
==============================================================================
--- sandbox/task/libs/task/examples/bind_to_processors.cpp (original)
+++ sandbox/task/libs/task/examples/bind_to_processors.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -18,7 +18,7 @@
 namespace pt = boost::posix_time;
 namespace tsk = boost::tasks;
 
-typedef tsk::static_pool< tsk::unbounded_onelock_fifo > pool_type;
+typedef tsk::static_pool< tsk::unbounded_fifo > pool_type;
 
 int serial_fib( int n)
 {

Modified: sandbox/task/libs/task/examples/interrupt.cpp
==============================================================================
--- sandbox/task/libs/task/examples/interrupt.cpp (original)
+++ sandbox/task/libs/task/examples/interrupt.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -17,7 +17,7 @@
 namespace pt = boost::posix_time;
 namespace tsk = boost::tasks;
 
-typedef tsk::static_pool< tsk::unbounded_twolock_fifo > pool_type;
+typedef tsk::static_pool< tsk::unbounded_fifo > pool_type;
 
 inline
 int fibonacci_fn( int n)

Modified: sandbox/task/libs/task/examples/priority.cpp
==============================================================================
--- sandbox/task/libs/task/examples/priority.cpp (original)
+++ sandbox/task/libs/task/examples/priority.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -29,7 +29,7 @@
 {
         try
         {
- tsk::static_pool< tsk::unbounded_onelock_prio_queue< int > > pool( tsk::poolsize( 1) );
+ tsk::static_pool< tsk::unbounded_prio_queue< int > > pool( tsk::poolsize( 1) );
 
                 tsk::task< void > t1( long_running_fn);
                 tsk::task< void > t2( print_fn, "a text.\n");

Modified: sandbox/task/libs/task/examples/shutdown_now.cpp
==============================================================================
--- sandbox/task/libs/task/examples/shutdown_now.cpp (original)
+++ sandbox/task/libs/task/examples/shutdown_now.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -40,7 +40,7 @@
 {
         try
         {
- tsk::static_pool< tsk::unbounded_onelock_fifo > pool( tsk::poolsize( 1) );
+ tsk::static_pool< tsk::unbounded_fifo > pool( tsk::poolsize( 1) );
 
                 tsk::task< int > t( fibonacci_fn, 10);
                                 

Modified: sandbox/task/libs/task/examples/smart.cpp
==============================================================================
--- sandbox/task/libs/task/examples/smart.cpp (original)
+++ sandbox/task/libs/task/examples/smart.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -49,7 +49,7 @@
         try
         {
                 tsk::static_pool<
- tsk::unbounded_onelock_smart_queue<
+ tsk::unbounded_smart_queue<
                                         int,
                                         std::less< int >
>

Modified: sandbox/task/libs/task/examples/sub_tasks.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sub_tasks.cpp (original)
+++ sandbox/task/libs/task/examples/sub_tasks.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -9,6 +9,7 @@
 #include <stdexcept>
 #include <vector>
 
+#include <boost/assert.hpp>
 #include <boost/bind.hpp>
 #include <boost/date_time/posix_time/posix_time.hpp>
 
@@ -17,7 +18,7 @@
 namespace pt = boost::posix_time;
 namespace tsk = boost::tasks;
 
-typedef tsk::static_pool< tsk::unbounded_twolock_fifo > pool_type;
+typedef tsk::static_pool< tsk::unbounded_fifo > pool_type;
 
 int serial_fib( int n)
 {
@@ -27,28 +28,32 @@
                 return serial_fib( n - 1) + serial_fib( n - 2);
 }
 
-int parallel_fib( int n, int cutof)
+int parallel_fib( int n, int cutof)
 {
- if ( n < cutof) return serial_fib( n);
+ if ( n < cutof)
+ {
+ return serial_fib( n);
+ }
         else
         {
                 BOOST_ASSERT( boost::this_task::runs_in_pool() );
- tsk::task< int > t1(
- parallel_fib,
- n - 1,
- cutof);
- tsk::task< int > t2(
- parallel_fib,
- n - 2,
- cutof);
+
                 tsk::handle< int > h1(
                         tsk::async(
- boost::move( t1),
- tsk::as_sub_task() ) ) ;
+ tsk::make_task(
+ parallel_fib,
+ n - 1,
+ cutof),
+ tsk::as_sub_task() ) );
+
                 tsk::handle< int > h2(
                         tsk::async(
- boost::move( t2),
+ tsk::make_task(
+ parallel_fib,
+ n - 2,
+ cutof),
                                 tsk::as_sub_task() ) );
+
                 return h1.get() + h2.get();
         }
 }
@@ -59,35 +64,16 @@
         {
                 pool_type pool( tsk::poolsize( 5) );
 
- std::vector< tsk::handle< int > > results;
- results.reserve( 10);
-
- pt::ptime start( pt::microsec_clock::universal_time() );
-
- for ( int i = 0; i < 10; ++i)
- {
- tsk::task< int > t(
- & parallel_fib,
- i,
- 5);
- results.push_back(
- tsk::async(
- boost::move( t),
- pool) );
- }
-
- tsk::waitfor_all( results.begin(), results.end() );
-
- int k = 0;
- std::vector< tsk::handle< int > >::iterator e( results.end() );
- for (
- std::vector< tsk::handle< int > >::iterator i( results.begin() );
- i != e;
- ++i)
- std::cout << "fibonacci(" << k++ << ") == " << i->get() << std::endl;
+ int n = 10;
+ tsk::handle< int > h(
+ tsk::async(
+ tsk::make_task(
+ parallel_fib,
+ n,
+ 5),
+ pool) );
 
- pt::ptime stop( pt::microsec_clock::universal_time() );
- std::cout << ( stop - start).total_milliseconds() << " milli seconds" << std::endl;
+ std::cout << "fibonacci(" << n << ") == " << h.get() << std::endl;
 
                 return EXIT_SUCCESS;
         }
@@ -98,3 +84,5 @@
 
         return EXIT_FAILURE;
 }
+
+

Modified: sandbox/task/libs/task/examples/submit.cpp
==============================================================================
--- sandbox/task/libs/task/examples/submit.cpp (original)
+++ sandbox/task/libs/task/examples/submit.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -35,7 +35,7 @@
 {
         try
         {
- tsk::static_pool< tsk::unbounded_onelock_prio_queue< int > > pool( tsk::poolsize( 3) );
+ tsk::static_pool< tsk::unbounded_prio_queue< int > > pool( tsk::poolsize( 3) );
 
                 tsk::task< int > t1( fibonacci_fn, 10);
                 tsk::task< int > t2( fibonacci_fn, 10);

Modified: sandbox/task/libs/task/examples/sync/fork_join_event.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sync/fork_join_event.cpp (original)
+++ sandbox/task/libs/task/examples/sync/fork_join_event.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -18,7 +18,7 @@
 
 namespace tsk = boost::tasks;
 
-typedef tsk::static_pool< tsk::unbounded_twolock_fifo > pool_type;
+typedef tsk::static_pool< tsk::unbounded_fifo > pool_type;
 
 void sub_task( int i, int n, tsk::spin::count_down_event & ev)
 {

Modified: sandbox/task/libs/task/examples/sync/message_passing.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sync/message_passing.cpp (original)
+++ sandbox/task/libs/task/examples/sync/message_passing.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -18,7 +18,7 @@
 
 namespace tsk = boost::tasks;
 
-typedef tsk::static_pool< tsk::unbounded_twolock_fifo > pool_type;
+typedef tsk::static_pool< tsk::unbounded_fifo > pool_type;
 
 int serial_fib( int n)
 {

Modified: sandbox/task/libs/task/examples/sync/ping_pong.cpp
==============================================================================
--- sandbox/task/libs/task/examples/sync/ping_pong.cpp (original)
+++ sandbox/task/libs/task/examples/sync/ping_pong.cpp 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -12,7 +12,7 @@
 
 #include <boost/task.hpp>
 
-typedef boost::tasks::static_pool< boost::tasks::unbounded_twolock_fifo > pool_t;
+typedef boost::tasks::static_pool< boost::tasks::unbounded_fifo > pool_t;
 typedef boost::tasks::spin::unbounded_channel< std::string > fifo_t;
 
 inline

Modified: sandbox/task/libs/task/test/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/test/Jamfile.v2 (original)
+++ sandbox/task/libs/task/test/Jamfile.v2 2009-12-30 07:14:29 EST (Wed, 30 Dec 2009)
@@ -31,7 +31,7 @@
     [ task-test test_new_thread ]
     [ task-test test_unbounded_pool ]
     [ task-test test_bounded_pool ]
-# [ task-test test_as_sub_task ]
+ [ task-test test_as_sub_task ]
     [ task-test test_spin_mutex ]
     [ task-test test_spin_condition ]
     [ task-test test_spin_condition_notify_all ]


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