|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52698 - in sandbox/task: boost/task boost/task/detail libs/task/examples
From: oliver.kowalke_at_[hidden]
Date: 2009-05-01 05:57:43
Author: olli
Date: 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
New Revision: 52698
URL: http://svn.boost.org/trac/boost/changeset/52698
Log:
* examples modified (async())
Text files modified:
sandbox/task/boost/task/async.hpp | 7 -------
sandbox/task/boost/task/default_pool.hpp | 2 +-
sandbox/task/boost/task/detail/atomic.hpp | 4 ++--
sandbox/task/libs/task/examples/bind_to_processors.cpp | 15 ++++++++++-----
sandbox/task/libs/task/examples/delay.cpp | 9 ++++++---
sandbox/task/libs/task/examples/fork_join.cpp | 16 ++++++++++------
sandbox/task/libs/task/examples/interrupt.cpp | 12 +++++++-----
sandbox/task/libs/task/examples/pending.cpp | 8 +++++---
sandbox/task/libs/task/examples/priority.cpp | 8 ++++----
sandbox/task/libs/task/examples/reschedule_until.cpp | 14 ++++++++++----
sandbox/task/libs/task/examples/shutdonw_now.cpp | 2 +-
sandbox/task/libs/task/examples/smart.cpp | 8 ++++----
sandbox/task/libs/task/examples/submit.cpp | 32 +++++++++++++++++++++++++++++---
sandbox/task/libs/task/examples/yield.cpp | 15 ++++++++++-----
14 files changed, 99 insertions(+), 53 deletions(-)
Modified: sandbox/task/boost/task/async.hpp
==============================================================================
--- sandbox/task/boost/task/async.hpp (original)
+++ sandbox/task/boost/task/async.hpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -63,13 +63,6 @@
}
};
-struct default_pool
-{
- template< typename R >
- handle< R > operator()( task< R > t)
- { return get_default_pool().submit( t); }
-};
-
template< typename Fn, typename R >
handle< R > async( Fn fn, task< R > t)
{ return fn( t); }
Modified: sandbox/task/boost/task/default_pool.hpp
==============================================================================
--- sandbox/task/boost/task/default_pool.hpp (original)
+++ sandbox/task/boost/task/default_pool.hpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -25,7 +25,7 @@
}
inline
-default_pool_t & get_default_pool()
+default_pool_t & default_pool()
{ return detail::static_pool::instance; }
} }
Modified: sandbox/task/boost/task/detail/atomic.hpp
==============================================================================
--- sandbox/task/boost/task/detail/atomic.hpp (original)
+++ sandbox/task/boost/task/detail/atomic.hpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -23,14 +23,14 @@
unsigned int atomic_fetch_add( volatile uint32_t * object, uint32_t operand)
{
BOOST_ASSERT( operand == 1);
- return interprocess::detail::atomic_dec32( object);
+ return interprocess::detail::atomic_inc32( object);
}
inline
unsigned int atomic_fetch_sub( volatile uint32_t * object, uint32_t operand)
{
BOOST_ASSERT( operand == 1);
- return interprocess::detail::atomic_inc32( object);
+ return interprocess::detail::atomic_dec32( object);
}
} } }
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-05-01 05:57:42 EDT (Fri, 01 May 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>
@@ -42,14 +43,17 @@
if ( n < cutof_) return serial_fib( n);
else
{
+ BOOST_ASSERT( boost::this_task::runs_in_pool() );
tsk::handle< long > h1(
- tsk::launch(
+ tsk::async(
+ boost::this_task::get_pool< pool_type >(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
n - 1) ) ) ;
tsk::handle< long > h2(
- tsk::launch(
+ tsk::async(
+ boost::this_task::get_pool< pool_type >(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
@@ -73,13 +77,14 @@
pool_type pool;
std::vector< tsk::handle< long > > results;
- results.reserve( 20);
+ results.reserve( 15);
pt::ptime start( pt::microsec_clock::universal_time() );
- for ( int i = 0; i < 26; ++i)
+ for ( int i = 0; i < 15; ++i)
results.push_back(
- tsk::launch(
+ tsk::async(
+ pool,
tsk::make_task(
& parallel_fib,
i) ) );
Modified: sandbox/task/libs/task/examples/delay.cpp
==============================================================================
--- sandbox/task/libs/task/examples/delay.cpp (original)
+++ sandbox/task/libs/task/examples/delay.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -46,13 +46,15 @@
else
{
tsk::handle< long > h1(
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
n - 1) ) );
tsk::handle< long > h2(
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
@@ -75,7 +77,8 @@
try
{
for ( int i = 0; i < 10; ++i)
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& parallel_fib,
i) );
Modified: sandbox/task/libs/task/examples/fork_join.cpp
==============================================================================
--- sandbox/task/libs/task/examples/fork_join.cpp (original)
+++ sandbox/task/libs/task/examples/fork_join.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -42,14 +42,17 @@
if ( n < cutof_) return serial_fib( n);
else
{
+ BOOST_ASSERT( boost::this_task::runs_in_pool() );
tsk::handle< long > h1(
- tsk::launch(
+ tsk::async(
+ boost::this_task::get_pool< pool_type >(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
- n - 1) ) );
+ n - 1) ) ) ;
tsk::handle< long > h2(
- tsk::launch(
+ tsk::async(
+ boost::this_task::get_pool< pool_type >(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
@@ -72,13 +75,14 @@
pool_type pool( tsk::poolsize( 5) );
std::vector< tsk::handle< long > > results;
- results.reserve( 20);
+ results.reserve( 15);
pt::ptime start( pt::microsec_clock::universal_time() );
- for ( int i = 0; i < 26; ++i)
+ for ( int i = 0; i < 15; ++i)
results.push_back(
- tsk::launch(
+ tsk::async(
+ pool,
tsk::make_task(
& parallel_fib,
i) ) );
Modified: sandbox/task/libs/task/examples/interrupt.cpp
==============================================================================
--- sandbox/task/libs/task/examples/interrupt.cpp (original)
+++ sandbox/task/libs/task/examples/interrupt.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -42,14 +42,16 @@
{
try
{
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
long_running_fn) );
- std::cout << "poolsize == " << tsk::get_default_pool().size() << std::endl;
- std::cout << "idle threads == " << tsk::get_default_pool().idle() << std::endl;
- std::cout << "active threads == " << tsk::get_default_pool().active() << std::endl;
+ std::cout << "poolsize == " << tsk::default_pool().size() << std::endl;
+ std::cout << "idle threads == " << tsk::default_pool().idle() << std::endl;
+ std::cout << "active threads == " << tsk::default_pool().active() << std::endl;
tsk::handle< int > h(
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
fibonacci_fn,
10) ) );
Modified: sandbox/task/libs/task/examples/pending.cpp
==============================================================================
--- sandbox/task/libs/task/examples/pending.cpp (original)
+++ sandbox/task/libs/task/examples/pending.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -43,15 +43,17 @@
{
try
{
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
long_running_fn) );
tsk::handle< int > h(
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
fibonacci_fn,
10) ) );
- std::cout << "pending tasks == " << tsk::get_default_pool().pending() << std::endl;
+ std::cout << "pending tasks == " << tsk::default_pool().pending() << std::endl;
std::cout << h.get() << std::endl;
return EXIT_SUCCESS;
Modified: sandbox/task/libs/task/examples/priority.cpp
==============================================================================
--- sandbox/task/libs/task/examples/priority.cpp (original)
+++ sandbox/task/libs/task/examples/priority.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -33,24 +33,24 @@
tsk::unbounded_channel< tsk::priority< int > >
> pool( tsk::poolsize( 1) );
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
long_running_fn),
0);
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
print_fn,
"This"),
0);
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
print_fn,
"a text.\n"),
2);
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
print_fn,
Modified: sandbox/task/libs/task/examples/reschedule_until.cpp
==============================================================================
--- sandbox/task/libs/task/examples/reschedule_until.cpp (original)
+++ sandbox/task/libs/task/examples/reschedule_until.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -19,6 +19,7 @@
#include <unistd.h>
}
+#include <boost/assert.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread.hpp>
@@ -51,14 +52,17 @@
if ( n < cutof_) return serial_fib( n);
else
{
+ BOOST_ASSERT( boost::this_task::runs_in_pool() );
tsk::handle< long > h1(
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
n - 1) ) );
tsk::handle< long > h2(
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
@@ -140,7 +144,8 @@
int fd[2];
create_sockets( fd);
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& do_read,
fd[0]) );
@@ -149,7 +154,8 @@
boost::this_thread::sleep( pt::seconds( 1) );
for ( int i = 0; i < 15; ++i)
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& parallel_fib,
i) );
Modified: sandbox/task/libs/task/examples/shutdonw_now.cpp
==============================================================================
--- sandbox/task/libs/task/examples/shutdonw_now.cpp (original)
+++ sandbox/task/libs/task/examples/shutdonw_now.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -45,7 +45,7 @@
> pool( tsk::poolsize( 1) );
tsk::handle< int > h(
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
fibonacci_fn,
Modified: sandbox/task/libs/task/examples/smart.cpp
==============================================================================
--- sandbox/task/libs/task/examples/smart.cpp (original)
+++ sandbox/task/libs/task/examples/smart.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -59,24 +59,24 @@
>
> pool( tsk::poolsize( 1) );
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
long_running_fn),
0);
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
fibonacci_fn,
0),
1);
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
fibonacci_fn,
1),
2);
- tsk::launch(
+ tsk::async(
pool,
tsk::make_task(
fibonacci_fn,
Modified: sandbox/task/libs/task/examples/submit.cpp
==============================================================================
--- sandbox/task/libs/task/examples/submit.cpp (original)
+++ sandbox/task/libs/task/examples/submit.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 2009)
@@ -35,12 +35,38 @@
{
try
{
- tsk::handle< int > h(
- tsk::launch(
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::own_thread(),
tsk::make_task(
fibonacci_fn,
10) ) );
- std::cout << h.get() << std::endl;
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::new_thread(),
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ tsk::handle< int > h3(
+ tsk::async(
+ tsk::default_pool(),
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ tsk::pool<
+ tsk::unbounded_channel< tsk::priority< int > >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< int > h4(
+ tsk::async(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ 2) );
+ std::cout << h1.get() << std::endl;
+ std::cout << h2.get() << std::endl;
+ std::cout << h3.get() << std::endl;
+ std::cout << h4.get() << std::endl;
return EXIT_SUCCESS;
}
Modified: sandbox/task/libs/task/examples/yield.cpp
==============================================================================
--- sandbox/task/libs/task/examples/yield.cpp (original)
+++ sandbox/task/libs/task/examples/yield.cpp 2009-05-01 05:57:42 EDT (Fri, 01 May 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::task;
-typedef tsk::default_pool pool_type;
+typedef tsk::default_pool_t pool_type;
long serial_fib( long n)
{
@@ -39,21 +40,24 @@
long execute( long n)
{
- if ( n == 7)
+ if ( n == 4)
boost::this_task::yield();
if ( n < cutof_)
return serial_fib( n);
else
{
+ BOOST_ASSERT( boost::this_task::runs_in_pool() );
tsk::handle< long > h1(
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
n - 1) ) );
tsk::handle< long > h2(
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
@@ -76,7 +80,8 @@
try
{
for ( int i = 0; i < 10; ++i)
- tsk::launch(
+ tsk::async(
+ tsk::default_pool(),
tsk::make_task(
& parallel_fib,
i) );
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