Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53901 - sandbox/task/libs/task/examples
From: oliver.kowalke_at_[hidden]
Date: 2009-06-14 06:16:25


Author: olli
Date: 2009-06-14 06:16:24 EDT (Sun, 14 Jun 2009)
New Revision: 53901
URL: http://svn.boost.org/trac/boost/changeset/53901

Log:
' test delay modified

Text files modified:
   sandbox/task/libs/task/examples/delay.cpp | 64 ++++++++++++++++-----------------------
   1 files changed, 26 insertions(+), 38 deletions(-)

Modified: sandbox/task/libs/task/examples/delay.cpp
==============================================================================
--- sandbox/task/libs/task/examples/delay.cpp (original)
+++ sandbox/task/libs/task/examples/delay.cpp 2009-06-14 06:16:24 EDT (Sun, 14 Jun 2009)
@@ -25,50 +25,38 @@
                 return serial_fib( n - 1) + serial_fib( n - 2);
 }
 
-class fib_task
+long parallel_fib_( long n, long cutof)
 {
-private:
- long cutof_;
-
-public:
- fib_task( long cutof)
- : cutof_( cutof)
- {}
-
- long execute( long n)
+ if ( n < cutof)
         {
- if ( n < cutof_)
- {
- if ( n == 0)
- boost::this_task::delay( pt::seconds( 2) );
- return serial_fib( n);
- }
- else
- {
- tsk::handle< long > h1(
- tsk::async(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 1),
- tsk::as_sub_task() ) );
- tsk::handle< long > h2(
- tsk::async(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 2),
- tsk::as_sub_task() ) );
- return h1.get() + h2.get();
- }
+ if ( n == 0)
+ boost::this_task::delay( pt::seconds( 2) );
+ return serial_fib( n);
         }
-};
-
+ else
+ {
+ BOOST_ASSERT( boost::this_task::runs_in_pool() );
+ tsk::handle< long > h1(
+ tsk::async(
+ tsk::make_task(
+ parallel_fib_,
+ n - 1,
+ cutof),
+ tsk::as_sub_task() ) ) ;
+ tsk::handle< long > h2(
+ tsk::async(
+ tsk::make_task(
+ parallel_fib_,
+ n - 2,
+ cutof),
+ tsk::as_sub_task() ) );
+ return h1.get() + h2.get();
+ }
+}
 
 void parallel_fib( long n)
 {
- fib_task a( 5);
- long result = a.execute( n);
+ long result = parallel_fib_( n, 5);
         printf("fibonnaci(%ld) == %ld\n", n, result);
 }
 


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