Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52693 - in sandbox/task: boost boost/task boost/task/detail libs/task/src libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2009-05-01 01:46:23


Author: olli
Date: 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
New Revision: 52693
URL: http://svn.boost.org/trac/boost/changeset/52693

Log:
* async() takes a function object which determines how the task is executed
        - own_thread, new_thread, default_pool, custom pool

Added:
   sandbox/task/boost/task/handle.hpp (contents, props changed)
Removed:
   sandbox/task/boost/task/async_handle.hpp
   sandbox/task/libs/task/test/test_launch.cpp
   sandbox/task/libs/task/test/test_pool_bounded_channel.cpp
   sandbox/task/libs/task/test/test_pool_unbounded_channel.cpp
Text files modified:
   sandbox/task/boost/task.hpp | 2
   sandbox/task/boost/task/async.hpp | 89 +++++++++++++++++++++------------------
   sandbox/task/boost/task/default_pool.hpp | 6 +-
   sandbox/task/boost/task/detail/thread_callable.hpp | 8 +-
   sandbox/task/boost/task/pool.hpp | 14 +++---
   sandbox/task/boost/task/task.hpp | 6 ++
   sandbox/task/libs/task/src/default_pool.cpp | 2
   7 files changed, 69 insertions(+), 58 deletions(-)

Modified: sandbox/task/boost/task.hpp
==============================================================================
--- sandbox/task/boost/task.hpp (original)
+++ sandbox/task/boost/task.hpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
@@ -8,12 +8,12 @@
 #define BOOST_TASK_H
 
 #include <boost/task/async.hpp>
-#include <boost/task/async_handle.hpp>
 #include <boost/task/bounded_channel.hpp>
 #include <boost/task/default_pool.hpp>
 #include <boost/task/exceptions.hpp>
 #include <boost/task/fifo.hpp>
 #include <boost/task/future.hpp>
+#include <boost/task/handle.hpp>
 #include <boost/task/id.hpp>
 #include <boost/task/info.hpp>
 #include <boost/task/pool.hpp>

Modified: sandbox/task/boost/task/async.hpp
==============================================================================
--- sandbox/task/boost/task/async.hpp (original)
+++ sandbox/task/boost/task/async.hpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
@@ -13,44 +13,13 @@
 #include <boost/task/default_pool.hpp>
 #include <boost/task/detail/interrupter.hpp>
 #include <boost/task/detail/thread_callable.hpp>
-#include <boost/task/async_handle.hpp>
+#include <boost/task/handle.hpp>
+#include <boost/task/future.hpp>
 #include <boost/task/pool.hpp>
 #include <boost/task/task.hpp>
 
 namespace boost { namespace task
 {
-template< typename R >
-async_handle< R > async_in_pool( task< R > t)
-{ return get_default_pool().submit( t); }
-
-template<
- typename R,
- typename Attr
->
-async_handle< R > async_in_pool(
- task< R > t,
- Attr const& attr)
-{ return get_default_pool().submit( t, attr); }
-
-template<
- typename Channel,
- typename R
->
-async_handle< R > async_in_pool(
- pool< Channel > & pool,
- task< R > t)
-{ return pool.submit( t); }
-
-template<
- typename Channel,
- typename R,
- typename Attr
->
-async_handle< R > async_in_pool(
- pool< Channel > & pool,
- task< R > t,
- Attr const& attr)
-{ return pool.submit( t, attr); }
 
 namespace detail
 {
@@ -64,17 +33,55 @@
 };
 }
 
-template< typename R >
-async_handle< R > async_in_thread( task< R > t)
+struct own_thread
 {
- detail::interrupter intr;
- detail::thread_callable ca( t, intr);
+ template< typename R >
+ handle< R > operator()( task< R > t)
+ {
+ t();
+ detail::interrupter intr;
+ intr.reset();
+ return handle< R >(
+ t.get_id(),
+ t.get_future(),
+ intr);
+ }
+};
 
- shared_ptr< thread > thrd( new thread( ca), detail::joiner() );
- intr.set( thrd);
+struct new_thread
+{
+ template< typename R >
+ handle< R > operator()( task< R > t)
+ {
+ detail::interrupter intr;
+ detail::thread_callable ca( t, intr);
+
+ shared_ptr< thread > thrd( new thread( ca), detail::joiner() );
+ intr.set( thrd);
+
+ return handle< R >( t.get_id(), t.get_future(), intr);
+ }
+};
+
+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); }
+
+template< typename R, typename Channel >
+handle< R > async( pool< Channel > & pool, task< R > t)
+{ return pool.submit( t); }
+
+template< typename R, typename Channel, typename Attr >
+handle< R > async( pool< Channel > & pool, task< R > t, Attr attr)
+{ return pool.submit( t, attr); }
 
- return async_handle< R >( t.get_id(), t.get_future(), intr);
-}
 } }
 
 #endif // BOOST_TASK_ASYNC_H

Deleted: sandbox/task/boost/task/async_handle.hpp
==============================================================================
--- sandbox/task/boost/task/async_handle.hpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
+++ (empty file)
@@ -1,289 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef BOOST_TASK_ASYNC_HANDLE_H
-#define BOOST_TASK_ASYNC_HANDLE_H
-
-#include <boost/thread.hpp>
-#include <boost/thread/thread_time.hpp>
-
-#include <boost/task/detail/interrupter.hpp>
-#include <boost/task/future.hpp>
-#include <boost/task/exceptions.hpp>
-#include <boost/task/id.hpp>
-
-namespace boost { namespace task
-{
-
-template< typename R >
-class async_handle;
-
-template< typename R >
-class task;
-
-template< typename Channel >
-class pool;
-
-template< typename R >
-async_handle< R > async_in_thread( task< R >);
-
-template< typename R >
-class async_handle
-{
-private:
- template< typename Channel >
- friend class pool;
- template< typename T >
- friend async_handle< T > async_in_thread( task< T >);
- template< typename Iterator >
- friend void waitfor_all( Iterator begin, Iterator end);
- template< typename T1, typename T2 >
- friend void waitfor_all( T1 & t1, T2 & t2);
- template< typename T1, typename T2, typename T3 >
- friend void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3);
- template< typename T1, typename T2, typename T3, typename T4 >
- friend void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4);
- template< typename T1, typename T2, typename T3, typename T4, typename T5 >
- friend void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4, async_handle< T5 > & t5);
- template< typename Iterator >
- friend Iterator waitfor_any( Iterator begin, Iterator end);
- template< typename T1, typename T2 >
- friend unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2);
- template< typename T1, typename T2, typename T3 >
- friend unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3);
- template< typename T1, typename T2, typename T3, typename T4 >
- friend unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4);
- template< typename T1, typename T2, typename T3, typename T4, typename T5 >
- friend unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4, async_handle< T5 > & t5);
-
- shared_future< R > fut_;
- detail::interrupter intr_;
- id id_;
-
- async_handle(
- id const& id__,
- shared_future< R > const& fut,
- detail::interrupter const& intr)
- :
- fut_( fut),
- intr_( intr),
- id_( id__)
- {}
-
-public:
- async_handle()
- : fut_(), intr_(), id_()
- {}
-
- const id get_id() const
- { return id_; }
-
- void interrupt()
- { intr_.interrupt(); }
-
- void interrupt_and_wait()
- { intr_.interrupt_and_wait(); }
-
- void interrupt_and_wait( system_time const& abs_time)
- { intr_.interrupt_and_wait( abs_time); }
-
- template< typename Duration >
- void interrupt_and_wait( Duration const& rel_time)
- { intr_.interrupt_and_wait( rel_time); }
-
- bool interruption_requested()
- { return intr_.interruption_requested(); }
-
- R get()
- {
- try
- { return fut_.get(); }
- catch ( broken_promise const&)
- { throw broken_task(); }
- catch ( promise_already_satisfied const&)
- { throw task_already_executed(); }
- }
-
- bool is_ready() const
- { return fut_.is_ready(); }
-
- bool has_value() const
- { return fut_.has_value(); }
-
- bool has_exception() const
- { return fut_.has_exception(); }
-
- void wait() const
- { fut_.wait(); }
-
- template< typename Duration >
- bool timed_wait( Duration const& rel_time) const
- { return fut_.timed_wait( rel_time); }
-
- bool timed_wait_until( system_time const& abs_time) const
- { return fut_.timed_wait_until( abs_time); }
-
- void swap( async_handle< R > & other)
- {
- fut_.swap( other.fut_);
- intr_.swap( other.intr_);
- id_.swap( other.id_);
- }
-};
-
-template<>
-class async_handle< void >
-{
-private:
- template< typename Channel >
- friend class pool;
- template< typename T >
- friend async_handle< T > async_in_thread( task< T >);
- template< typename Iterator >
- friend void waitfor_all( Iterator begin, Iterator end);
- template< typename T1, typename T2 >
- friend void waitfor_all( T1 & t1, T2 & t2);
- template< typename T1, typename T2, typename T3 >
- friend void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3);
- template< typename T1, typename T2, typename T3, typename T4 >
- friend void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4);
- template< typename T1, typename T2, typename T3, typename T4, typename T5 >
- friend void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4, async_handle< T5 > & t5);
- template< typename Iterator >
- friend Iterator waitfor_any( Iterator begin, Iterator end);
- template< typename T1, typename T2 >
- friend unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2);
- template< typename T1, typename T2, typename T3 >
- friend unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3);
- template< typename T1, typename T2, typename T3, typename T4 >
- friend unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4);
- template< typename T1, typename T2, typename T3, typename T4, typename T5 >
- friend unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4, async_handle< T5 > & t5);
-
- shared_future< void > fut_;
- detail::interrupter intr_;
- id id_;
-
- async_handle(
- id const& id__,
- shared_future< void > const& fut,
- detail::interrupter const& intr)
- :
- fut_( fut),
- intr_( intr),
- id_( id__)
- {}
-
-
-public:
- async_handle()
- : fut_(), intr_(), id_()
- {}
-
- const id get_id() const
- { return id_; }
-
- void interrupt()
- { intr_.interrupt(); }
-
- void interrupt_and_wait()
- { intr_.interrupt_and_wait(); }
-
- void interrupt_and_wait( system_time const& abs_time)
- { intr_.interrupt_and_wait( abs_time); }
-
- template< typename Duration >
- void interrupt_and_wait( Duration const& rel_time)
- { intr_.interrupt_and_wait( rel_time); }
-
- bool interruption_requested()
- { return intr_.interruption_requested(); }
-
- void get()
- {
- try
- { fut_.get(); }
- catch ( broken_promise const&)
- { throw broken_task(); }
- }
-
- bool is_ready() const
- { return fut_.is_ready(); }
-
- bool has_value() const
- { return fut_.has_value(); }
-
- bool has_exception() const
- { return fut_.has_exception(); }
-
- void wait() const
- { fut_.wait(); }
-
- template< typename Duration >
- bool timed_wait( Duration const& rel_time) const
- { return fut_.timed_wait( rel_time); }
-
- bool timed_wait_until( system_time const& abs_time) const
- { return fut_.timed_wait_until( abs_time); }
-
- void swap( async_handle< void > & other)
- {
- fut_.swap( other.fut_);
- intr_.swap( other.intr_);
- }
-};
-
-template< typename Iterator >
-void waitfor_all( Iterator begin, Iterator end)
-{
- for ( Iterator i = begin; i != end; ++i)
- i->wait();
-}
-
-template< typename T1, typename T2 >
-void waitfor_all( T1 & t1, T2 & t2)
-{ wait_for_all( t1.fut_, t2.fut_); }
-
-template< typename T1, typename T2, typename T3 >
-void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3)
-{ wait_for_all( t1.fut_, t2.fut_, t3.fut_); }
-
-template< typename T1, typename T2, typename T3, typename T4 >
-void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4)
-{ wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
-
-template< typename T1, typename T2, typename T3, typename T4, typename T5 >
-void waitfor_all( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4, async_handle< T5 > & t5)
-{ wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
-
-template< typename Iterator >
-Iterator waitfor_any( Iterator begin, Iterator end)
-{
- boost::detail::future_waiter waiter;
- for ( Iterator i = begin; i != end; ++i)
- waiter.add( i->fut_);
- return next( begin, waiter.wait() );
-}
-
-template< typename T1, typename T2 >
-unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2)
-{ return wait_for_any( t1.fut_, t2.fut_); }
-
-template< typename T1, typename T2, typename T3 >
-unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3)
-{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_); }
-
-template< typename T1, typename T2, typename T3, typename T4 >
-unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4)
-{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
-
-template< typename T1, typename T2, typename T3, typename T4, typename T5 >
-unsigned int waitfor_any( async_handle< T1 > & t1, async_handle< T2 > & t2, async_handle< T3 > & t3, async_handle< T4 > & t4, async_handle< T5 > & t5)
-{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
-
-}}
-
-#endif // BOOST_TASK_ASYNC_HANDLE_H

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 01:46:21 EDT (Fri, 01 May 2009)
@@ -16,16 +16,16 @@
 
 namespace boost { namespace task
 {
-typedef pool< unbounded_channel< fifo > > default_pool;
+typedef pool< unbounded_channel< fifo > > default_pool_t;
 
 namespace detail
 {
 struct BOOST_TASK_DECL static_pool
-{ static default_pool instance; };
+{ static default_pool_t instance; };
 }
 
 inline
-default_pool & get_default_pool()
+default_pool_t & get_default_pool()
 { return detail::static_pool::instance; }
 } }
 

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-05-01 01:46:21 EDT (Fri, 01 May 2009)
@@ -45,11 +45,11 @@
                 : t_( t), i_( i)
                 {}
 
+ ~impl_wrapper()
+ { i_.reset(); }
+
                 void run()
- {
- t_();
- i_.reset();
- }
+ { t_(); }
         };
 
         shared_ptr< impl > impl_;

Added: sandbox/task/boost/task/handle.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/handle.hpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
@@ -0,0 +1,283 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TASK_HANDLE_H
+#define BOOST_TASK_HANDLE_H
+
+#include <boost/thread.hpp>
+#include <boost/thread/thread_time.hpp>
+
+#include <boost/task/detail/interrupter.hpp>
+#include <boost/task/future.hpp>
+#include <boost/task/exceptions.hpp>
+#include <boost/task/id.hpp>
+
+namespace boost { namespace task
+{
+
+template< typename Channel >
+class pool;
+
+struct own_thread;
+struct new_thread;
+
+template< typename R >
+class handle
+{
+private:
+ template< typename Channel >
+ friend class pool;
+ friend struct own_thread;
+ friend struct new_thread;
+ template< typename Iterator >
+ friend void waitfor_all( Iterator begin, Iterator end);
+ template< typename T1, typename T2 >
+ friend void waitfor_all( T1 & t1, T2 & t2);
+ template< typename T1, typename T2, typename T3 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3);
+ template< typename T1, typename T2, typename T3, typename T4 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4);
+ template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
+ template< typename Iterator >
+ friend Iterator waitfor_any( Iterator begin, Iterator end);
+ template< typename T1, typename T2 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2);
+ template< typename T1, typename T2, typename T3 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3);
+ template< typename T1, typename T2, typename T3, typename T4 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4);
+ template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
+
+ shared_future< R > fut_;
+ detail::interrupter intr_;
+ id id_;
+
+ handle(
+ id const& id__,
+ shared_future< R > const& fut,
+ detail::interrupter const& intr)
+ :
+ fut_( fut),
+ intr_( intr),
+ id_( id__)
+ {}
+
+public:
+ handle()
+ : fut_(), intr_(), id_()
+ {}
+
+ const id get_id() const
+ { return id_; }
+
+ void interrupt()
+ { intr_.interrupt(); }
+
+ void interrupt_and_wait()
+ { intr_.interrupt_and_wait(); }
+
+ void interrupt_and_wait( system_time const& abs_time)
+ { intr_.interrupt_and_wait( abs_time); }
+
+ template< typename Duration >
+ void interrupt_and_wait( Duration const& rel_time)
+ { intr_.interrupt_and_wait( rel_time); }
+
+ bool interruption_requested()
+ { return intr_.interruption_requested(); }
+
+ R get()
+ {
+ try
+ { return fut_.get(); }
+ catch ( broken_promise const&)
+ { throw broken_task(); }
+ catch ( promise_already_satisfied const&)
+ { throw task_already_executed(); }
+ }
+
+ bool is_ready() const
+ { return fut_.is_ready(); }
+
+ bool has_value() const
+ { return fut_.has_value(); }
+
+ bool has_exception() const
+ { return fut_.has_exception(); }
+
+ void wait() const
+ { fut_.wait(); }
+
+ template< typename Duration >
+ bool timed_wait( Duration const& rel_time) const
+ { return fut_.timed_wait( rel_time); }
+
+ bool timed_wait_until( system_time const& abs_time) const
+ { return fut_.timed_wait_until( abs_time); }
+
+ void swap( handle< R > & other)
+ {
+ fut_.swap( other.fut_);
+ intr_.swap( other.intr_);
+ id_.swap( other.id_);
+ }
+};
+
+template<>
+class handle< void >
+{
+private:
+ template< typename Channel >
+ friend class pool;
+ friend struct own_thread;
+ friend struct new_thread;
+ template< typename Iterator >
+ friend void waitfor_all( Iterator begin, Iterator end);
+ template< typename T1, typename T2 >
+ friend void waitfor_all( T1 & t1, T2 & t2);
+ template< typename T1, typename T2, typename T3 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3);
+ template< typename T1, typename T2, typename T3, typename T4 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4);
+ template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
+ template< typename Iterator >
+ friend Iterator waitfor_any( Iterator begin, Iterator end);
+ template< typename T1, typename T2 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2);
+ template< typename T1, typename T2, typename T3 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3);
+ template< typename T1, typename T2, typename T3, typename T4 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4);
+ template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
+
+ shared_future< void > fut_;
+ detail::interrupter intr_;
+ id id_;
+
+ handle(
+ id const& id__,
+ shared_future< void > const& fut,
+ detail::interrupter const& intr)
+ :
+ fut_( fut),
+ intr_( intr),
+ id_( id__)
+ {}
+
+
+public:
+ handle()
+ : fut_(), intr_(), id_()
+ {}
+
+ const id get_id() const
+ { return id_; }
+
+ void interrupt()
+ { intr_.interrupt(); }
+
+ void interrupt_and_wait()
+ { intr_.interrupt_and_wait(); }
+
+ void interrupt_and_wait( system_time const& abs_time)
+ { intr_.interrupt_and_wait( abs_time); }
+
+ template< typename Duration >
+ void interrupt_and_wait( Duration const& rel_time)
+ { intr_.interrupt_and_wait( rel_time); }
+
+ bool interruption_requested()
+ { return intr_.interruption_requested(); }
+
+ void get()
+ {
+ try
+ { fut_.get(); }
+ catch ( broken_promise const&)
+ { throw broken_task(); }
+ }
+
+ bool is_ready() const
+ { return fut_.is_ready(); }
+
+ bool has_value() const
+ { return fut_.has_value(); }
+
+ bool has_exception() const
+ { return fut_.has_exception(); }
+
+ void wait() const
+ { fut_.wait(); }
+
+ template< typename Duration >
+ bool timed_wait( Duration const& rel_time) const
+ { return fut_.timed_wait( rel_time); }
+
+ bool timed_wait_until( system_time const& abs_time) const
+ { return fut_.timed_wait_until( abs_time); }
+
+ void swap( handle< void > & other)
+ {
+ fut_.swap( other.fut_);
+ intr_.swap( other.intr_);
+ }
+};
+
+template< typename Iterator >
+void waitfor_all( Iterator begin, Iterator end)
+{
+ for ( Iterator i = begin; i != end; ++i)
+ i->wait();
+}
+
+template< typename T1, typename T2 >
+void waitfor_all( T1 & t1, T2 & t2)
+{ wait_for_all( t1.fut_, t2.fut_); }
+
+template< typename T1, typename T2, typename T3 >
+void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3)
+{ wait_for_all( t1.fut_, t2.fut_, t3.fut_); }
+
+template< typename T1, typename T2, typename T3, typename T4 >
+void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4)
+{ wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
+
+template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5)
+{ wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
+
+template< typename Iterator >
+Iterator waitfor_any( Iterator begin, Iterator end)
+{
+ boost::detail::future_waiter waiter;
+ for ( Iterator i = begin; i != end; ++i)
+ waiter.add( i->fut_);
+ return next( begin, waiter.wait() );
+}
+
+template< typename T1, typename T2 >
+unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2)
+{ return wait_for_any( t1.fut_, t2.fut_); }
+
+template< typename T1, typename T2, typename T3 >
+unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3)
+{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_); }
+
+template< typename T1, typename T2, typename T3, typename T4 >
+unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4)
+{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
+
+template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5)
+{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
+
+}}
+
+#endif // BOOST_TASK_HANDLE_H

Modified: sandbox/task/boost/task/pool.hpp
==============================================================================
--- sandbox/task/boost/task/pool.hpp (original)
+++ sandbox/task/boost/task/pool.hpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
@@ -27,7 +27,7 @@
 #include <boost/task/detail/worker_group.hpp>
 #include <boost/task/exceptions.hpp>
 #include <boost/task/future.hpp>
-#include <boost/task/async_handle.hpp>
+#include <boost/task/handle.hpp>
 #include <boost/task/poolsize.hpp>
 #include <boost/task/scanns.hpp>
 #include <boost/task/task.hpp>
@@ -285,7 +285,7 @@
         { return channel_.lower_bound( lwm); }
 
         template< typename R >
- async_handle< R > submit( task< R > t)
+ handle< R > submit( task< R > t)
         {
                 detail::interrupter intr;
                 shared_future< R > fut( t.get_future() );
@@ -302,7 +302,7 @@
                                         w,
                                         wcb) );
                         w->put( detail::pool_callable( t, intr) );
- return async_handle< R >( t.get_id(), fut, intr);
+ return handle< R >( t.get_id(), fut, intr);
                 }
                 else
                 {
@@ -310,7 +310,7 @@
                                 throw task_rejected("pool is closed");
 
                         channel_.put( detail::pool_callable( t, intr) );
- return async_handle< R >( t.get_id(), fut, intr);
+ return handle< R >( t.get_id(), fut, intr);
                 }
         }
 
@@ -318,7 +318,7 @@
                 typename R,
                 typename Attr
>
- async_handle< R > submit( task< R > t, Attr const& attr)
+ handle< R > submit( task< R > t, Attr const& attr)
         {
                 detail::interrupter intr;
                 shared_future< R > fut( t.get_future() );
@@ -335,7 +335,7 @@
                                         w,
                                         wcb) );
                         w->put( detail::pool_callable( t, intr) );
- return async_handle< R >( t.get_id(), fut, intr);
+ return handle< R >( t.get_id(), fut, intr);
                 }
                 else
                 {
@@ -343,7 +343,7 @@
                                 throw task_rejected("pool is closed");
 
                         channel_.put( channel_item( detail::pool_callable( t, intr), attr) );
- return async_handle< R >( t.get_id(), fut, intr);
+ return handle< R >( t.get_id(), fut, intr);
                 }
         }
 };

Modified: sandbox/task/boost/task/task.hpp
==============================================================================
--- sandbox/task/boost/task/task.hpp (original)
+++ sandbox/task/boost/task/task.hpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
@@ -22,7 +22,7 @@
 
 #include <boost/task/future.hpp>
 #include <boost/task/exceptions.hpp>
-#include <boost/task/async_handle.hpp>
+#include <boost/task/handle.hpp>
 #include <boost/task/id.hpp>
 
 namespace boost { namespace task
@@ -64,6 +64,8 @@
                 {
                         try
                         { impl::prom.set_value( fn_() ); }
+ catch ( promise_already_satisfied const&)
+ { /*FIXME: should we absorb promise_already_satisfied? */ }
                         catch ( thread_interrupted const&)
                         { impl::prom.set_exception( copy_exception( task_interrupted() ) ); }
                         catch ( boost::exception const& e)
@@ -165,6 +167,8 @@
                                 fn_();
                                 impl::prom.set_value();
                         }
+ catch ( promise_already_satisfied const&)
+ { /*FIXME: should we absorb promise_already_satisfied? */ }
                         catch ( thread_interrupted const&)
                         { impl::prom.set_exception( copy_exception( task_interrupted() ) ); }
                         catch ( boost::exception const& e)

Modified: sandbox/task/libs/task/src/default_pool.cpp
==============================================================================
--- sandbox/task/libs/task/src/default_pool.cpp (original)
+++ sandbox/task/libs/task/src/default_pool.cpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
@@ -14,7 +14,7 @@
 {
 namespace detail
 {
-default_pool
+default_pool_t
 static_pool::instance( poolsize( thread::hardware_concurrency() ) );
 }
 } }

Deleted: sandbox/task/libs/task/test/test_launch.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_launch.cpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
+++ (empty file)
@@ -1,124 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-class test_launch
-{
-public:
- // launch in default pool
- void test_case_1()
- {
- tsk::handle< int > h(
- tsk::launch(
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // launch in custom pool
- void test_case_2()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::handle< int > h(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // launch in current thread
- void test_case_3()
- {
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- t();
- tsk::handle< int > h( t.get_handle() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // don't execute twice
- void test_case_4()
- {
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::handle< int > h( t.get_handle() );
- tsk::launch( t);
- BOOST_CHECK_EQUAL( h.get(), 55);
-// tsk::launch( t);
-// bool thrown( false);
-// try
-// { h.get(); }
-// catch ( tsk::task_already_executed const&)
-// { thrown = true; }
-// BOOST_CHECK( thrown);
- }
-
- // check runs in pool
- void test_case_5()
- {
- tsk::handle< bool > h(
- tsk::launch(
- tsk::make_task(
- runs_in_pool_fn) ) );
- BOOST_CHECK_EQUAL( h.get(), true);
- }
-
- // check runs not in pool
- void test_case_6()
- {
- tsk::task< bool > t(
- tsk::make_task(
- runs_in_pool_fn) );
- t();
- tsk::handle< bool > h( t.get_handle() );
- BOOST_CHECK_EQUAL( h.get(), false);
- }
-};
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
-
- boost::shared_ptr< test_launch > instance( new test_launch() );
- test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_6, instance) );
-
- return test;
-}

Deleted: sandbox/task/libs/task/test/test_pool_bounded_channel.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_pool_bounded_channel.cpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
+++ (empty file)
@@ -1,426 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-class test_pool_bounded_channel
-{
-public:
- // check size, active, idle
- void test_case_1()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 3),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
- }
-
- // check submit
- void test_case_2()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::handle< int > h(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check shutdown
- void test_case_3()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::handle< int > h(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runtime_error throw inside task
- void test_case_4()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::handle< void > h(
- tsk::launch(
- pool,
- tsk::make_task(
- throwing_fn) ) );
- pool.shutdown();
- bool thrown( false);
- try
- { h.get(); }
- catch ( std::runtime_error const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown with task_rejected exception
- void test_case_5()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- bool thrown( false);
- try
- {
- tsk::launch(
- pool,
- tsk::make_task(
- boost::bind(
- fibonacci_fn,
- 10) ) );
- }
- catch ( tsk::task_rejected const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown_now with thread_interrupted exception
- void test_case_6()
- {
- tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::handle< void > h(
- tsk::launch(
- pool,
- tsk::make_task(
- delay_fn,
- pt::millisec( 500) ) ) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- pool.shutdown_now();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
- BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check pending
- void test_case_7()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::handle< void > h1(
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) ) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
- tsk::handle< int > h2(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- boost::this_thread::sleep( pt::millisec(250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
- tsk::handle< int > h3(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- boost::this_thread::sleep( pt::millisec(250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
- b.wait();
- h1.get();
- BOOST_CHECK_EQUAL( h2.get(), 55);
- BOOST_CHECK_EQUAL( h3.get(), 55);
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
- }
-
- // check interruption
- void test_case_8()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::handle< void > h(
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) ) );
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- h.interrupt();
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check fifo scheduling
- void test_case_9()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) );
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check lifo scheduling
- void test_case_10()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::lifo >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) );
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 55);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check priority scheduling
- void test_case_11()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::priority< int > >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- 0);
- std::vector< int > buffer;
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
- 1);
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- 0);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 55);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check smart scheduling
- void test_case_12()
- {
- typedef tsk::pool<
- tsk::bounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- 0);
- std::vector< int > buffer;
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
- 2);
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- 1);
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 1),
- 2);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 1);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-};
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
-
- boost::shared_ptr< test_pool_bounded_channel > instance( new test_pool_bounded_channel() );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_6, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_7, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_8, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_9, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_10, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_11, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_12, instance) );
-
- return test;
-}
-

Deleted: sandbox/task/libs/task/test/test_pool_unbounded_channel.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_pool_unbounded_channel.cpp 2009-05-01 01:46:21 EDT (Fri, 01 May 2009)
+++ (empty file)
@@ -1,387 +0,0 @@
-
-// Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include <cstdlib>
-#include <iostream>
-#include <map>
-#include <stdexcept>
-#include <vector>
-
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/function.hpp>
-#include <boost/ref.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/thread.hpp>
-#include <boost/thread/barrier.hpp>
-#include <boost/utility.hpp>
-
-#include <boost/task.hpp>
-
-#include "test_functions.hpp"
-
-namespace pt = boost::posix_time;
-namespace tsk = boost::task;
-
-class test_pool_unbounded_channel
-{
-public:
- // check size, active, idle
- void test_case_1()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 3) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
- }
-
- // check submit
- void test_case_2()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::handle< int > h(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check shutdown
- void test_case_3()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::handle< int > h(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runtime_error throw inside task
- void test_case_4()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::handle< void > h(
- tsk::launch(
- pool,
- tsk::make_task(
- throwing_fn) ) );
- pool.shutdown();
- bool thrown( false);
- try
- { h.get(); }
- catch ( std::runtime_error const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown with task_rejected exception
- void test_case_5()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- bool thrown( false);
- try
- {
- tsk::launch(
- pool,
- tsk::make_task(
- boost::bind(
- fibonacci_fn,
- 10) ) );
- }
- catch ( tsk::task_rejected const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check shutdown_now with thread_interrupted exception
- void test_case_6()
- {
- tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
- tsk::handle< void > h(
- tsk::launch(
- pool,
- tsk::make_task(
- delay_fn,
- pt::millisec( 500) ) ) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- pool.shutdown_now();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
- BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
- BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check pending
- void test_case_7()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- tsk::handle< void > h1(
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) ) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
- tsk::handle< int > h2(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- boost::this_thread::sleep( pt::millisec(250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
- tsk::handle< int > h3(
- tsk::launch(
- pool,
- tsk::make_task(
- fibonacci_fn,
- 10) ) );
- boost::this_thread::sleep( pt::millisec(250) );
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
- b.wait();
- h1.get();
- BOOST_CHECK_EQUAL( h2.get(), 55);
- BOOST_CHECK_EQUAL( h3.get(), 55);
- BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
- }
-
- // check interruptation
- void test_case_8()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- pool.submit(
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::handle< void > h(
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) ) );
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- h.interrupt();
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
- bool thrown( false);
- try
- { h.get(); }
- catch ( tsk::task_interrupted const&)
- { thrown = true; }
- BOOST_CHECK( thrown);
- }
-
- // check fifo scheduling
- void test_case_9()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) );
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 55);
- BOOST_CHECK_EQUAL( buffer[1], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check lifo scheduling
- void test_case_10()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::lifo >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ) );
- std::vector< int > buffer;
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) );
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0) );
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 55);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check priority scheduling
- void test_case_11()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::priority< int > >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- tsk::launch(
- pool,
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- 0);
- std::vector< int > buffer;
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
- 1);
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- 0);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 55);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-
- // check smart scheduling
- void test_case_12()
- {
- typedef tsk::pool<
- tsk::unbounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
- > pool_type;
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- pool.submit(
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- 0);
- std::vector< int > buffer;
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
- 2);
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- 1);
- tsk::launch(
- pool,
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 1),
- 2);
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer[1], 1);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
- }
-};
-
-boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
-{
- boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
-
- boost::shared_ptr< test_pool_unbounded_channel > instance( new test_pool_unbounded_channel() );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_6, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_7, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_8, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_9, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_10, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_11, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_12, instance) );
-
- return test;
-}


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