|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53861 - in sandbox/task: . boost/task boost/task/detail libs/task/doc libs/task/src libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2009-06-13 03:56:52
Author: olli
Date: 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
New Revision: 53861
URL: http://svn.boost.org/trac/boost/changeset/53861
Log:
* fucntions interrupt_and_wait_for() and interrupt_and_wait-until() return boolean
* documetnation updated
* tests updated
Text files modified:
sandbox/task/boost/task/detail/interrupter.hpp | 14
sandbox/task/boost/task/handle.hpp | 98 ++++++++-
sandbox/task/change.log | 14
sandbox/task/libs/task/doc/ref_async.qbk | 6
sandbox/task/libs/task/doc/ref_handle.qbk | 63 ++++--
sandbox/task/libs/task/doc/ref_new_thread.qbk | 2
sandbox/task/libs/task/doc/ref_static_pool.qbk | 38 +-
sandbox/task/libs/task/doc/ref_task.qbk | 2
sandbox/task/libs/task/doc/ref_utility.qbk | 28 +-
sandbox/task/libs/task/src/interrupter.cpp | 11
sandbox/task/libs/task/test/test_bounded_pool.cpp | 385 +++++++++++++++++++++++++++++++++------
sandbox/task/libs/task/test/test_default_pool.cpp | 91 ++++++--
sandbox/task/libs/task/test/test_functions.hpp | 8
sandbox/task/libs/task/test/test_new_thread.cpp | 225 ++++++++++++++++++++--
sandbox/task/libs/task/test/test_own_thread.cpp | 236 ++++++++++++++++++++++--
sandbox/task/libs/task/test/test_unbounded_pool.cpp | 339 +++++++++++++++++++++++++++++-----
16 files changed, 1273 insertions(+), 287 deletions(-)
Modified: sandbox/task/boost/task/detail/interrupter.hpp
==============================================================================
--- sandbox/task/boost/task/detail/interrupter.hpp (original)
+++ sandbox/task/boost/task/detail/interrupter.hpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -62,14 +62,16 @@
void interrupt_and_wait();
- void interrupt_and_wait_until( system_time const& abs_time);
+ bool interrupt_and_wait_until( system_time const& abs_time);
template< typename DurationType >
- void interrupt_and_wait_for( DurationType const& rel_time)
+ bool interrupt_and_wait_for( DurationType const& rel_time)
{
unique_lock< mutex > lk( mtx_);
interrupt_();
- cond_.timed_wait( lk, rel_time);
+ if ( ! done_)
+ return cond_.timed_wait( lk, rel_time);
+ return true;
}
bool interruption_requested();
@@ -88,11 +90,11 @@
void interrupt_and_wait();
- void interrupt_and_wait_until( system_time const& abs_time);
+ bool interrupt_and_wait_until( system_time const& abs_time);
template< typename DurationType >
- void interrupt_and_wait_for( DurationType const& rel_time)
- { impl_->interrupt_and_wait_for( rel_time); }
+ bool interrupt_and_wait_for( DurationType const& rel_time)
+ { return impl_->interrupt_and_wait_for( rel_time); }
bool interruption_requested();
Modified: sandbox/task/boost/task/handle.hpp
==============================================================================
--- sandbox/task/boost/task/handle.hpp (original)
+++ sandbox/task/boost/task/handle.hpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -85,12 +85,12 @@
void interrupt_and_wait()
{ intr_.interrupt_and_wait(); }
- void interrupt_and_wait_until( system_time const& abs_time)
- { intr_.interrupt_and_wait_until( abs_time); }
+ bool interrupt_and_wait_until( system_time const& abs_time)
+ { return intr_.interrupt_and_wait_until( abs_time); }
template< typename Duration >
- void interrupt_and_wait_for( Duration const& rel_time)
- { intr_.interrupt_and_wait_for( rel_time); }
+ bool interrupt_and_wait_for( Duration const& rel_time)
+ { return intr_.interrupt_and_wait_for( rel_time); }
bool interruption_requested()
{ return intr_.interruption_requested(); }
@@ -122,6 +122,10 @@
{ 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 Duration >
@@ -131,6 +135,10 @@
{ return fut_.timed_wait( rel_time); }
catch ( future_uninitialized const&)
{ throw task_uninitialized(); }
+ catch ( broken_promise const&)
+ { throw broken_task(); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
}
bool wait_until( system_time const& abs_time) const
@@ -139,6 +147,10 @@
{ return fut_.timed_wait_until( abs_time); }
catch ( future_uninitialized const&)
{ throw task_uninitialized(); }
+ catch ( broken_promise const&)
+ { throw broken_task(); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
}
shared_future< R > & get_future()
@@ -155,50 +167,100 @@
template< typename Iterator >
void waitfor_all( Iterator begin, Iterator end)
{
- for ( Iterator i = begin; i != end; ++i)
- i->wait();
+ try
+ {
+ for ( Iterator i = begin; i != end; ++i)
+ i->wait();
+ }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
}
template< typename T1, typename T2 >
void waitfor_all( T1 & t1, T2 & t2)
-{ wait_for_all( t1.fut_, t2.fut_); }
+{
+ try
+ { wait_for_all( t1.fut_, t2.fut_); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
+}
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_); }
+{
+ try
+ { wait_for_all( t1.fut_, t2.fut_, t3.fut_); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
+}
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_); }
+{
+ try
+ { wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
+}
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_); }
+{
+ try
+ { wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
+}
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() );
+ try
+ {
+ boost::detail::future_waiter waiter;
+ for ( Iterator i = begin; i != end; ++i)
+ waiter.add( i->fut_);
+ return next( begin, waiter.wait() );
+ }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
}
template< typename T1, typename T2 >
unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2)
-{ return wait_for_any( t1.fut_, t2.fut_); }
+{
+ try
+ { return wait_for_any( t1.fut_, t2.fut_); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
+}
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_); }
+{
+ try
+ { return wait_for_any( t1.fut_, t2.fut_, t3.fut_); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
+}
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_); }
+{
+ try
+ { return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
+}
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_); }
+{
+ try
+ { return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
+ catch ( thread_interrupted const&)
+ { throw task_interrupted(); }
+}
}}
Modified: sandbox/task/change.log
==============================================================================
--- sandbox/task/change.log (original)
+++ sandbox/task/change.log 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -1,8 +1,10 @@
* boost.task-0.2:
-----------------
-- detail/atomic.hpp splitt into several headers for different platforms
- - xchg for gcc && x86
- - lwarx for gcc && powrepc
-- new function shared_future< R > handle< R >::get_future()
-- new_thread, own_thread and as_sub_task in separat headers
-- async() with as_sub_task as default async. executor
+- detail/atomic.hpp with atomic_exchange (gcc + x86|ppc)
+- handle< R > with new function get_future() returning reference to internal shared future
+- moved execution-policies new_thread, own_thread and as_sub_task in separat headers
+- async() with as_sub_task as default execution-policy
+- functions interrupt_and_wait_until() and interrupt_and_wait_for() from handle< R > returning
+ boolean indicating if op. succeeded or timed out
+- tests updated
+- documentation updated
\ No newline at end of file
Modified: sandbox/task/libs/task/doc/ref_async.qbk
==============================================================================
--- sandbox/task/libs/task/doc/ref_async.qbk (original)
+++ sandbox/task/libs/task/doc/ref_async.qbk 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -17,7 +17,7 @@
[variablelist
[[Effects:] [executes task in an asyncrounous executer and returns a handle associated with the task]]
-[[Throws:] [Nothing]]
+[[Throws:] [`boost::thread_resource_error`]]
]
[endsect]
@@ -34,7 +34,7 @@
[variablelist
[[Effects:] [executes task in a thread-pool and returns a handle associated with the task]]
-[[Throws:] [Nothing]]
+[[Throws:] [`boost::task::task_rejected`]]
]
[endsect]
@@ -51,7 +51,7 @@
[variablelist
[[Effects:] [executes atrributed task in a thread-pool and returns a handle associated with the task]]
-[[Throws:] [Nothing]]
+[[Throws:] [`boost::task::task_rejected`]]
]
[endsect]
Modified: sandbox/task/libs/task/doc/ref_handle.qbk
==============================================================================
--- sandbox/task/libs/task/doc/ref_handle.qbk (original)
+++ sandbox/task/libs/task/doc/ref_handle.qbk 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -110,7 +110,7 @@
[variablelist
[[Effects:] [requests task interruption; doesn not block (immediatly returns)]]
-[[Throws:] [???]]
+[[Throws:] [Nothing]]
]
@@ -120,28 +120,30 @@
[variablelist
[[Effects:] [requests task interruption and blocks until worker-thread stops task]]
-[[Throws:] [???]]
+[[Throws:] [`boost::thread_resource_error`]]
]
[heading Member function `interrupt_and_wait_until()`]
- void interrupt_and_wait_until( system_time const& abs_time)
+ bool interrupt_and_wait_until( system_time const& abs_time)
[variablelist
[[Effects:] [requests task interruption and blocks until worker-thread stops task or time-point elapsed]]
-[[Throws:] [???]]
+[[Returns:] [false if the the time specified by abs_time was reached, true otherwise]]
+[[Throws:] [`boost::thread_resource_error`]]
]
[heading Member function `interrupt_and_wait_for()`]
template< typename Duration >
- void interrupt_and_wait_for( Duration const& rel_time)
+ bool interrupt_and_wait_for( Duration const& rel_time)
[variablelist
[[Effects:] [requests task interruption and blocks until worker-thread stops task or time-duration elapsed]]
-[[Throws:] [???]]
+[[Returns:] [false if the the time specified by rel_time was reached, true otherwise]]
+[[Throws:] [`boost::thread_resource_error`]]
]
@@ -151,7 +153,7 @@
[variablelist
[[Effects:] [requests the result]]
-[[Throws:] [task_interrupted, task_uninialized]]
+[[Throws:] [`boost::task::task_interrupted`, `boost::task::task_uninialized`, `boost::task::task_rejected`, `boost::task::broken_task`]]
]
@@ -161,7 +163,28 @@
[variablelist
[[Effects:] [blocks caller until task is done]]
-[[Throws:] [task_interrupted, task_uninialized]]
+[[Throws:] [`boost::task::task_interrupted`, `boost::task::task_uninialized`, `boost::task::task_rejected`, `boost::task::broken_task`]]
+]
+
+
+[heading Member function `wait_for()`]
+
+ template< typename Duration >
+ bool wait_for( Duration const& rel_time) const
+
+[variablelist
+[[Effects:] [blocks caller until task is done]]
+[[Throws:] [`boost::task::task_interrupted`, `boost::task::task_uninialized`, `boost::task::task_rejected`, `boost::task::broken_task`]]
+]
+
+
+[heading Member function `wait_until()`]
+
+ bool wait_until( system_time const& abs_time) const
+
+[variablelist
+[[Effects:] [blocks caller until task is done]]
+[[Throws:] [`boost::task::task_interrupted`, `boost::task::task_uninialized`, `boost::task::task_rejected`, `boost::task::broken_task`]]
]
@@ -218,46 +241,46 @@
[heading Non-member function `wait_for_all()`]
template< typename Iterator >
- friend void waitfor_all( Iterator begin, Iterator end);
+ void waitfor_all( Iterator begin, Iterator end);
template< typename T1, typename T2 >
- friend void waitfor_all( T1 & t1, T2 & t2);
+ 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);
+ 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);
+ 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);
+ void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
[variablelist
[[Effects:] [waits for all handles to become ready]]
-[[Throws:] [Nothing]]
+[[Throws:] [`boost::task::task_interrupted`, `boost::task::task_rejected`]]
]
[heading Non-member function `wait_for_any()`]
template< typename Iterator >
- friend Iterator waitfor_any( Iterator begin, Iterator end);
+ Iterator waitfor_any( Iterator begin, Iterator end);
template< typename T1, typename T2 >
- friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2);
+ 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);
+ 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);
+ 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);
+ unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
[variablelist
[[Effects:] [waits for any handle to become ready]]
-[[Throws:] [Nothing]]
+[[Throws:] [`boost::task::task_interrupted`, `boost::task::task_rejected`, `std::bad_alloc`]]
]
Modified: sandbox/task/libs/task/doc/ref_new_thread.qbk
==============================================================================
--- sandbox/task/libs/task/doc/ref_new_thread.qbk (original)
+++ sandbox/task/libs/task/doc/ref_new_thread.qbk 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -25,7 +25,7 @@
[variablelist
[[Effects:] [executes task in a new thread an returns an handle associated with the task]]
-[[Throws:] [Nothing]]
+[[Throws:] [`boost::thread_resource_error`]]
]
Modified: sandbox/task/libs/task/doc/ref_static_pool.qbk
==============================================================================
--- sandbox/task/libs/task/doc/ref_static_pool.qbk (original)
+++ sandbox/task/libs/task/doc/ref_static_pool.qbk 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -74,7 +74,7 @@
[variablelist
[[Preconditions:] [operating system provides functionality for processor pining]]
[[Effects:] [constructs a pool - for each processor a worker-thread is created and bound to one processor - global-queue can queue an unlimited number of tasks]]
-[[Throws:] [`boost::task::invalid_scanns`, `boost::task::invalid_timeduration`]]
+[[Throws:] [`boost::thread_resource_error`, `boost::task::invalid_scanns`, `boost::task::invalid_timeduration`]]
[[Notes:] [constructor has to be called if a unbounded-channel is used]]
]
@@ -88,7 +88,7 @@
[variablelist
[[Effects:] [constructs a pool containing psize worker-threads - global-queue can queue an unlimited number of tasks]]
-[[Throws:] [`boost::task::invalid_scanns`, `boost::task::invalid_timeduration`]]
+[[Throws:] [`boost::thread_resource_error`, `boost::task::invalid_scanns`, `boost::task::invalid_timeduration`]]
[[Notes:] [constructor has to be called if a unbounded-channel is used]]
]
@@ -104,8 +104,8 @@
[variablelist
[[Preconditions:] [operating system provides functionality for processor pining]]
[[Effects:] [constructs a pool - for each processor a worker-thread is created and bound to one processor - global-queue can only queue a limited number of tasks]]
-[[Throws:] [`boost::task::invalid_scanns`, `boost::task::invalid_timeduration`, `boost::task::invalid_watermark`]]
-[[Notes:] [Constructor has to be called if a bounded-channel is used.]]
+[[Throws:] [`boost::thread_resource_error`, `boost::task::invalid_scanns`, `boost::task::invalid_timeduration`, `boost::task::invalid_watermark`]]
+[[Notes:] [constructor has to be called if a bounded-channel is used]]
]
@@ -120,7 +120,7 @@
[variablelist
[[Effects:] [constructs a pool containing psize worker-threads - global-queue can only queue a limited number of tasks]]
-[[Throws:] [`boost::task::invalid_scanns`, `boost::task::invalid_timeduration`, `boost::task::invalid_watermark`]]
+[[Throws:] [`boost::thread_resource_error`, `boost::task::invalid_scanns`, `boost::task::invalid_timeduration`, `boost::task::invalid_watermark`]]
[[Notes:] [constructor has to be called if a bounded-channel is used]]
]
@@ -130,8 +130,8 @@
~static_pool()
[variablelist
-[[Effects:] [calls `:shutdown()` if not already called]]
-[[Throws:] [Nothing]]
+[[Effects:] [calls `shutdown()` if not already called]]
+[[Throws:] [nothing]]
]
@@ -141,7 +141,7 @@
[variablelist
[[Effects:] [returns how many worker-threads are running in the pool]]
-[[Throws:] [Nothing]]
+[[Throws:] [nothing]]
]
@@ -151,7 +151,7 @@
[variablelist
[[Effects:] [returns how many worker-threads are active (executing an task)]]
-[[Throws:] [Nothing]]
+[[Throws:] [nothing]]
]
@@ -161,8 +161,8 @@
[variablelist
[[Effects:] [returns how many worker-threads are idle (not executing an task).]]
-[[Throws:] [Nothing]]
-[[Notes:] [The value is the difference of `size()` and `active()`]]
+[[Throws:] [nothing]]
+[[Notes:] [the value is the difference of `size()` and `active()`]]
]
@@ -172,7 +172,7 @@
[variablelist
[[Effects:] [deactivates the channel and joins all worker-threads - the pool is closed]]
-[[Throws:] [Nothing]]
+[[Throws:] [`boost::thread_interrupted`, `boost::system::system_error`]]
[[Notes:] [all pending tasks are processed]]
]
@@ -183,7 +183,7 @@
[variablelist
[[Effects:] [deactivates the channel, send interruption request to all worker-threads and joins them - the pool is closed]]
-[[Throws:] [Nothing]]
+[[Throws:] [`boost::thread_interrupted`, `boost::system::system_error`]]
[[Notes:] [pending tasks are not processed but returned]]
]
@@ -194,7 +194,7 @@
[variablelist
[[Effects:] [queries if the pool is closed (pool is shutdown)]]
-[[Throws:] [Nothing]]
+[[Throws:] [nothing]]
]
@@ -204,7 +204,7 @@
[variablelist
[[Effects:] [removes all pending tasks from the channel]]
-[[Throws:] [Nothing]]
+[[Throws:] [nothing]]
]
@@ -214,7 +214,7 @@
[variablelist
[[Effects:] [queries if the channel is empty]]
-[[Throws:] [Nothing]]
+[[Throws:] [nothing]]
]
@@ -224,7 +224,7 @@
[variablelist
[[Effects:] [queries how many tasks are pending (still unprocessed) in the global-queue (channel)]]
-[[Throws:] [Nothing]]
+[[Throws:] [nothing]]
]
@@ -235,7 +235,7 @@
[variablelist
[[Preconditions:] [channel is of type bounded-channel]]
[[Effects:] [returns the upper bound of the bounded-channel]]
-[[Throws:] [Nothing]]
+[[Throws:] [nothing]]
[[Notes:] [can only be used if a bounded-channel is used]]
]
@@ -260,7 +260,7 @@
[variablelist
[[Preconditions:] [channel is of type bounded-channel]]
[[Effects:] [returns the lower bound of the bounded-channel]]
-[[Throws:] [Nothing]]
+[[Throws:] [nothing]]
[[Notes:] [can only be used if a bounded-channel is used]]
]
Modified: sandbox/task/libs/task/doc/ref_task.qbk
==============================================================================
--- sandbox/task/libs/task/doc/ref_task.qbk (original)
+++ sandbox/task/libs/task/doc/ref_task.qbk 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -62,7 +62,7 @@
[variablelist
[[Effects:] [returns a future assiciated with the task]]
-[[Throws:] [???]]
+[[Throws:] [Nothing]]
]
Modified: sandbox/task/libs/task/doc/ref_utility.qbk
==============================================================================
--- sandbox/task/libs/task/doc/ref_utility.qbk (original)
+++ sandbox/task/libs/task/doc/ref_utility.qbk 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -17,8 +17,8 @@
[variablelist
[[Effects:] [reschedules current task until passed callable predicate becomes ready]
-[[Throws:] [Nothing.]]
-[[Note:] [This function resides in namespace `boost::this_task`.]]
+[[Throws:] [`boost::thread_interrupted`,`boost::system::system_error`]]
+[[Note:] [this function resides in namespace `boost::this_task`]]
]
[endsect]
@@ -35,8 +35,8 @@
[variablelist
[[Effects:] [returns reference to the thread-pool where the current worker thread is executed]
-[[Throws:] [Nothing.]]
-[[Note:] [This function resides in namespace `boost::this_task`.]]
+[[Throws:] [nothing]]
+[[Note:] [this function resides in namespace `boost::this_task`]]
]
[endsect]
@@ -52,8 +52,8 @@
[variablelist
[[Effects:] [returns true if the current task is executed in a thread-pool]
-[[Throws:] [Nothing.]]
-[[Note:] [This function resides in namespace `boost::this_task`.]]
+[[Throws:] [nothing]]
+[[Note:] [this function resides in namespace `boost::this_task`]]
]
[endsect]
@@ -69,8 +69,8 @@
[variablelist
[[Effects:] [returns returns the thread-id of the worker-thread]
-[[Throws:] [Nothing.]]
-[[Note:] [This function resides in namespace `boost::this_task`.]]
+[[Throws:] [nothing]]
+[[Note:] [this function resides in namespace `boost::this_task`]]
]
[endsect]
@@ -89,8 +89,8 @@
[variablelist
[[Effects:] [delays the execution of the current task so that the worker-thread can process another task in the meantime]
-[[Throws:] [Nothing.]]
-[[Note:] [This function resides in namespace `boost::this_task`.]]
+[[Throws:] [nothing]]
+[[Note:] [this function resides in namespace `boost::this_task`]]
]
[endsect]
@@ -106,8 +106,8 @@
[variablelist
[[Effects:] [yields the current task so that the worker-threadcan process another task in the meantime]
-[[Throws:] [Nothing.]]
-[[Note:] [This function resides in namespace `boost::this_task`.]]
+[[Throws:] [nothing]]
+[[Note:] [this function resides in namespace `boost::this_task`]]
]
[endsect]
@@ -123,8 +123,8 @@
[variablelist
[[Effects:] [task can request interruption for itself]
-[[Throws:] [Nothing.]]
-[[Note:] [This function resides in namespace `boost::this_task`.]]
+[[Throws:] [nothing]]
+[[Note:] [this function resides in namespace `boost::this_task`]]
]
[endsect]
Modified: sandbox/task/libs/task/src/interrupter.cpp
==============================================================================
--- sandbox/task/libs/task/src/interrupter.cpp (original)
+++ sandbox/task/libs/task/src/interrupter.cpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -73,13 +73,14 @@
cond_.wait( lk);
}
-void
+bool
interrupter::impl::interrupt_and_wait_until( system_time const& abs_time)
{
unique_lock< mutex > lk( mtx_);
interrupt_();
- while ( ! done_)
- cond_.timed_wait( lk, abs_time);
+ if ( ! done_)
+ return cond_.timed_wait( lk, abs_time);
+ return true;
}
bool
@@ -109,9 +110,9 @@
interrupter::interrupt_and_wait()
{ impl_->interrupt_and_wait(); }
-void
+bool
interrupter::interrupt_and_wait_until( system_time const& abs_time)
-{ impl_->interrupt_and_wait_until( abs_time); }
+{ return impl_->interrupt_and_wait_until( abs_time); }
bool
interrupter::interruption_requested()
Modified: sandbox/task/libs/task/test/test_bounded_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_bounded_pool.cpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -62,12 +62,86 @@
BOOST_CHECK_EQUAL( h.get(), 55);
}
- // check runs in pool
+ // check id
void test_case_3()
{
tsk::static_pool<
tsk::bounded_channel< tsk::fifo >
> pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h(
+ tsk::async(
+ t,
+ pool) );
+ BOOST_CHECK_EQUAL( h.get_id(), t.get_id() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check assignment
+ void test_case_4()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ pool) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get_id(), h2.get_id() );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check swap
+ void test_case_5()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 5),
+ pool) );
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ pool) );
+ BOOST_CHECK_EQUAL( h1.get(), 5);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_NO_THROW( h1.swap( h2) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 5);
+ }
+
+ // check runs in pool
+ void test_case_6()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
tsk::poolsize( 1),
tsk::high_watermark( 10),
tsk::low_watermark( 10) );
@@ -78,33 +152,8 @@
BOOST_CHECK_EQUAL( h.get(), true);
}
- // executed twice
-// void test_case_4()
-// {
-// tsk::static_pool<
-// tsk::bounded_channel< tsk::fifo >
-// > pool(
-// tsk::poolsize( 1),
-// tsk::high_watermark( 10),
-// tsk::low_watermark( 10) );
-// tsk::task< int > t(
-// tsk::make_task(
-// fibonacci_fn,
-// 10) );
-// tsk::handle< int > h1(
-// tsk::async(
-// pool,
-// t) );
-// BOOST_CHECK_EQUAL( h1.get(), 55);
-// BOOST_CHECK_THROW(
-// tsk::async(
-// pool,
-// t),
-// tsk::task_already_executed);
-// }
-
// check shutdown
- void test_case_5()
+ void test_case_7()
{
tsk::static_pool<
tsk::bounded_channel< tsk::fifo >
@@ -124,7 +173,7 @@
}
// check runtime_error throw inside task
- void test_case_6()
+ void test_case_8()
{
tsk::static_pool<
tsk::bounded_channel< tsk::fifo >
@@ -141,7 +190,7 @@
}
// check shutdown with task_rejected exception
- void test_case_7()
+ void test_case_9()
{
tsk::static_pool<
tsk::bounded_channel< tsk::fifo >
@@ -162,7 +211,7 @@
}
// check shutdown_now with thread_interrupted exception
- void test_case_8()
+ void test_case_10()
{
tsk::static_pool<
tsk::bounded_channel< tsk::fifo >
@@ -187,7 +236,7 @@
}
// check pending
- void test_case_9()
+ void test_case_11()
{
typedef tsk::static_pool<
tsk::bounded_channel< tsk::fifo >
@@ -228,46 +277,248 @@
BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
}
- // check interruption
- void test_case_10()
+ // check wait
+ void test_case_12()
{
- typedef tsk::static_pool<
+ tsk::static_pool<
tsk::bounded_channel< tsk::fifo >
- > pool_type;
- pool_type pool(
- tsk::poolsize( 1),
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::handle< int > h(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ pool) );
+ h.wait();
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check wait_for
+ void test_case_13()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 1) ),
+ pool) );
+ BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_14()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ),
+ pool) );
+ BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_15()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 1) ),
+ pool) );
+ BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_16()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ),
+ pool) );
+ BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check interrupt
+ void test_case_17()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
tsk::high_watermark( 10),
tsk::low_watermark( 10) );
- boost::barrier b( 2);
- tsk::async(
- tsk::make_task(
- barrier_fn,
- boost::ref( b) ),
- pool);
- std::vector< int > buffer;
tsk::handle< void > h(
tsk::async(
tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10),
+ delay_fn,
+ pt::seconds( 3) ),
pool) );
- tsk::async(
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- pool);
h.interrupt();
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+ }
+
+ // check interrupt_and_wait
+ void test_case_18()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ pool) );
+ h.interrupt_and_wait();
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+ }
+
+ // check interrupt_and_wait_for
+ void test_case_19()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ pool) );
+ BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
}
+ // check interrupt_and_wait_for
+ void test_case_20()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ non_interrupt_fn,
+ 3),
+ pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+ }
+
+ // check interrupt_and_wait_until
+ void test_case_21()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ pool) );
+ BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+ }
+
+ // check interrupt_and_wait_until
+ void test_case_22()
+ {
+ tsk::static_pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ non_interrupt_fn,
+ 3),
+ pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ }
+
// check fifo scheduling
- void test_case_11()
+ void test_case_23()
{
typedef tsk::static_pool<
tsk::bounded_channel< tsk::fifo >
@@ -304,7 +555,7 @@
}
// check priority scheduling
- void test_case_12()
+ void test_case_24()
{
typedef tsk::static_pool<
tsk::bounded_channel< tsk::priority< int > >
@@ -346,7 +597,7 @@
}
// check smart scheduling
- void test_case_13()
+ void test_case_25()
{
typedef tsk::static_pool<
tsk::bounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
@@ -403,7 +654,7 @@
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_1, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_2, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_3, instance) );
-// test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_4, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_5, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_6, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_7, instance) );
@@ -413,6 +664,18 @@
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_11, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_12, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_13, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_14, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_15, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_16, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_17, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_18, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_19, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_20, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_21, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_22, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_23, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_24, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_bounded_pool::test_case_25, instance) );
return test;
}
Modified: sandbox/task/libs/task/test/test_default_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_default_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_default_pool.cpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -44,9 +44,47 @@
BOOST_CHECK_EQUAL( h.get(), 55);
}
- // check runs in pool
+ // check assignment
void test_case_2()
{
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::default_pool() ) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get_id(), h2.get_id() );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check swap
+ void test_case_3()
+ {
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 5),
+ tsk::default_pool() ) );
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::default_pool() ) );
+ BOOST_CHECK_EQUAL( h1.get(), 5);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_NO_THROW( h1.swap( h2) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 5);
+ }
+
+ // check runs in pool
+ void test_case_4()
+ {
tsk::handle< bool > h(
tsk::async(
tsk::make_task( runs_in_pool_fn),
@@ -54,27 +92,8 @@
BOOST_CHECK_EQUAL( h.get(), true);
}
- // executed twice
-// void test_case_3()
-// {
-// tsk::task< int > t(
-// tsk::make_task(
-// fibonacci_fn,
-// 10) );
-// tsk::handle< int > h1(
-// tsk::async(
-// tsk::default_pool(),
-// t) );
-// BOOST_CHECK_EQUAL( h1.get(), 55);
-// BOOST_CHECK_THROW(
-// tsk::async(
-// tsk::default_pool(),
-// t),
-// tsk::task_already_executed);
-// }
-
// check runtime_error throw inside task
- void test_case_4()
+ void test_case_5()
{
tsk::handle< void > h(
tsk::async(
@@ -84,7 +103,7 @@
}
// check interrupt
- void test_case_5()
+ void test_case_6()
{
tsk::handle< void > h(
tsk::async(
@@ -98,7 +117,7 @@
}
// check interrupt_and_wait
- void test_case_6()
+ void test_case_7()
{
bool finished( false);
tsk::handle< void > h(
@@ -111,12 +130,30 @@
h.interrupt_and_wait();
BOOST_CHECK( finished);
BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
BOOST_CHECK( h.interruption_requested() );
BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
}
+ // check wait
+ void test_case_8()
+ {
+ tsk::handle< int > h(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::default_pool() ) );
+ h.wait();
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
// check waitfor_all()
- void test_case_7()
+ void test_case_9()
{
std::vector< tsk::handle< int > > vec;
for ( int i = 0; i <= 5; ++i)
@@ -142,7 +179,7 @@
}
// check waitfor_any()
- void test_case_8()
+ void test_case_10()
{
tsk::handle< void > h1(
tsk::async(
@@ -170,12 +207,14 @@
boost::shared_ptr< test_default_pool > instance( new test_default_pool() );
test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_1, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_2, instance) );
-// test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_3, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_4, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_5, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_6, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_7, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_9, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_default_pool::test_case_10, instance) );
return test;
}
Modified: sandbox/task/libs/task/test/test_functions.hpp
==============================================================================
--- sandbox/task/libs/task/test/test_functions.hpp (original)
+++ sandbox/task/libs/task/test/test_functions.hpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -13,6 +13,11 @@
#include <stdexcept>
#include <vector>
+extern "C"
+{
+#include <unistd.h>
+}
+
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/function.hpp>
@@ -34,6 +39,9 @@
void delay_fn( pt::time_duration const& td)
{ boost::this_thread::sleep( td); }
+void non_interrupt_fn( int sec)
+{ ::sleep( sec); }
+
void interrupt_fn( pt::time_duration const& td, bool & finished)
{
try
Modified: sandbox/task/libs/task/test/test_new_thread.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_new_thread.cpp (original)
+++ sandbox/task/libs/task/test/test_new_thread.cpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -44,9 +44,47 @@
BOOST_CHECK_EQUAL( h.get(), 55);
}
- // check runs not in pool
+ // check assignment
void test_case_2()
{
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::new_thread() ) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get_id(), h2.get_id() );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check swap
+ void test_case_3()
+ {
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 5),
+ tsk::new_thread() ) );
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::new_thread() ) );
+ BOOST_CHECK_EQUAL( h1.get(), 5);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_NO_THROW( h1.swap( h2) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 5);
+ }
+
+ // check runs not in pool
+ void test_case_4()
+ {
tsk::handle< bool > h(
tsk::async(
tsk::make_task( runs_in_pool_fn),
@@ -54,27 +92,8 @@
BOOST_CHECK_EQUAL( h.get(), false);
}
- // executed twice
-// void test_case_3()
-// {
-// tsk::task< int > t(
-// tsk::make_task(
-// fibonacci_fn,
-// 10) );
-// tsk::handle< int > h1(
-// tsk::async(
-// tsk::new_thread(),
-// t) );
-// BOOST_CHECK_EQUAL( h1.get(), 55);
-// BOOST_CHECK_THROW(
-// tsk::async(
-// tsk::new_thread(),
-// t),
-// tsk::task_already_executed);
-// }
-
// check runtime_error throw inside task
- void test_case_4()
+ void test_case_5()
{
tsk::handle< void > h(
tsk::async(
@@ -83,8 +102,84 @@
BOOST_CHECK_THROW( h.get(), std::runtime_error);
}
+ // check wait
+ void test_case_6()
+ {
+ tsk::handle< int > h(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::new_thread() ) );
+ h.wait();
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check wait_for
+ void test_case_7()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 1) ),
+ tsk::new_thread() ) );
+ BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_8()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ),
+ tsk::new_thread() ) );
+ BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_9()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 1) ),
+ tsk::new_thread() ) );
+ BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_10()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ),
+ tsk::new_thread() ) );
+ BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
// check interrupt
- void test_case_5()
+ void test_case_11()
{
tsk::handle< void > h(
tsk::async(
@@ -98,25 +193,91 @@
}
// check interrupt_and_wait
- void test_case_6()
+ void test_case_12()
{
bool finished( false);
tsk::handle< void > h(
tsk::async(
tsk::make_task(
interrupt_fn,
- pt::seconds( 3),
+ pt::seconds( 1),
boost::ref( finished) ),
tsk::new_thread() ) );
h.interrupt_and_wait();
BOOST_CHECK( finished);
BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+ }
+
+ // check interrupt_and_wait_for
+ void test_case_13()
+ {
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ tsk::new_thread() ) );
+ BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
BOOST_CHECK( h.interruption_requested() );
BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
}
+ // check interrupt_and_wait_for
+ void test_case_14()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ non_interrupt_fn,
+ 3),
+ tsk::new_thread() ) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+ }
+
+ // check interrupt_and_wait_until
+ void test_case_15()
+ {
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ tsk::new_thread() ) );
+ BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+ }
+
+ // check interrupt_and_wait_until
+ void test_case_16()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ non_interrupt_fn,
+ 3),
+ tsk::new_thread() ) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ }
+
// check waitfor_all()
- void test_case_7()
+ void test_case_17()
{
std::vector< tsk::handle< int > > vec;
for ( int i = 0; i <= 5; ++i)
@@ -142,7 +303,7 @@
}
// check waitfor_any()
- void test_case_8()
+ void test_case_18()
{
tsk::handle< void > h1(
tsk::async(
@@ -170,12 +331,22 @@
boost::shared_ptr< test_new_thread > instance( new test_new_thread() );
test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_1, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_2, instance) );
-// test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_3, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_4, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_5, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_6, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_7, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_9, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_10, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_11, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_12, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_13, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_14, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_15, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_16, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_17, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_new_thread::test_case_18, instance) );
return test;
}
Modified: sandbox/task/libs/task/test/test_own_thread.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_own_thread.cpp (original)
+++ sandbox/task/libs/task/test/test_own_thread.cpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -44,9 +44,47 @@
BOOST_CHECK_EQUAL( h.get(), 55);
}
- // check runs not in pool
+ // check assignment
void test_case_2()
{
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::own_thread() ) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get_id(), h2.get_id() );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check swap
+ void test_case_3()
+ {
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 5),
+ tsk::own_thread() ) );
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::own_thread() ) );
+ BOOST_CHECK_EQUAL( h1.get(), 5);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_NO_THROW( h1.swap( h2) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 5);
+ }
+
+ // check runs not in pool
+ void test_case_4()
+ {
tsk::handle< bool > h(
tsk::async(
tsk::make_task( runs_in_pool_fn),
@@ -54,23 +92,8 @@
BOOST_CHECK_EQUAL( h.get(), false);
}
- // executed twice
-// void test_case_3()
-// {
-// tsk::task< int > t(
-// tsk::make_task(
-// fibonacci_fn,
-// 10) );
-// tsk::handle< int > h1(
-// tsk::async(
-// tsk::own_thread(),
-// t) );
-// BOOST_CHECK_EQUAL( h1.get(), 55);
-// BOOST_CHECK_THROW( tsk::async( tsk::own_thread(), t), tsk::task_already_executed);
-// }
-
// check runtime_error throw inside task
- void test_case_4()
+ void test_case_5()
{
tsk::handle< void > h(
tsk::async(
@@ -80,7 +103,7 @@
}
// check task_uninitialized
- void test_case_5()
+ void test_case_6()
{
tsk::handle< int > h;
BOOST_CHECK_THROW( h.get(), tsk::task_uninitialized);
@@ -94,8 +117,84 @@
BOOST_CHECK( ! h.has_exception() );
}
+ // check wait
+ void test_case_7()
+ {
+ tsk::handle< int > h(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ tsk::own_thread() ) );
+ h.wait();
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check wait_for
+ void test_case_8()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 1) ),
+ tsk::own_thread() ) );
+ BOOST_CHECK( h.wait_for( pt::seconds( 2) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_9()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 2) ),
+ tsk::own_thread() ) );
+ BOOST_CHECK( h.wait_for( pt::seconds( 1) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_10()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 1) ),
+ tsk::own_thread() ) );
+ BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_11()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 2) ),
+ tsk::own_thread() ) );
+ BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
// check interrupt
- void test_case_6()
+ void test_case_12()
{
tsk::handle< void > h(
tsk::async(
@@ -109,7 +208,7 @@
}
// check interrupt_and_wait
- void test_case_7()
+ void test_case_13()
{
bool finished( false);
tsk::handle< void > h(
@@ -126,8 +225,74 @@
BOOST_CHECK_NO_THROW( h.get() );
}
+ // check interrupt_and_wait_for
+ void test_case_14()
+ {
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ tsk::own_thread() ) );
+ BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 2) ) );
+ BOOST_CHECK( ! finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_NO_THROW( h.get() );
+ }
+
+ // check interrupt_and_wait_for
+ void test_case_15()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ non_interrupt_fn,
+ 2),
+ tsk::own_thread() ) );
+ BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 1) ) );
+ BOOST_CHECK_NO_THROW( h.get() );
+ }
+
+ // check interrupt_and_wait_until
+ void test_case_16()
+ {
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ tsk::own_thread() ) );
+ BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 2) ) );
+ BOOST_CHECK( ! finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_NO_THROW( h.get() );
+ }
+
+ // check interrupt_and_wait_until
+ void test_case_17()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ non_interrupt_fn,
+ 2),
+ tsk::own_thread() ) );
+ BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ BOOST_CHECK_NO_THROW( h.get() );
+ }
+
// check waitfor_all()
- void test_case_8()
+ void test_case_18()
{
std::vector< tsk::handle< int > > vec;
for ( int i = 0; i <= 5; ++i)
@@ -153,7 +318,7 @@
}
// check waitfor_any()
- void test_case_9()
+ void test_case_19()
{
tsk::handle< void > h1(
tsk::async(
@@ -172,6 +337,20 @@
BOOST_CHECK( h2.is_ready() );
BOOST_CHECK_EQUAL( h2.get(), 55);
}
+
+ // check interrupt + wait
+ void test_case_20()
+ {
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ),
+ tsk::own_thread() ) );
+ h.interrupt();
+ BOOST_CHECK_NO_THROW( h.wait() );
+ BOOST_CHECK_NO_THROW( h.get() );
+ }
};
boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
@@ -181,13 +360,24 @@
boost::shared_ptr< test_own_thread > instance( new test_own_thread() );
test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_1, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_2, instance) );
-// test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_3, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_4, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_5, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_6, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_7, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_8, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_9, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_10, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_11, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_12, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_13, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_14, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_15, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_16, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_17, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_18, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_19, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_own_thread::test_case_20, instance) );
return test;
}
Modified: sandbox/task/libs/task/test/test_unbounded_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_unbounded_pool.cpp 2009-06-13 03:56:51 EDT (Sat, 13 Jun 2009)
@@ -46,7 +46,7 @@
{
tsk::static_pool<
tsk::unbounded_channel< tsk::fifo >
- > pool( tsk::poolsize( 1) );
+ > pool( tsk::poolsize( 3) );
tsk::handle< int > h(
tsk::async(
tsk::make_task(
@@ -56,11 +56,73 @@
BOOST_CHECK_EQUAL( h.get(), 55);
}
- // check runs in pool
+ // check id
void test_case_3()
{
tsk::static_pool<
tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::handle< int > h(
+ tsk::async(
+ t,
+ pool) );
+ BOOST_CHECK_EQUAL( h.get_id(), t.get_id() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check assignment
+ void test_case_4()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ pool) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get_id(), h2.get_id() );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ }
+
+ // check swap
+ void test_case_5()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< int > h1(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 5),
+ pool) );
+ tsk::handle< int > h2(
+ tsk::async(
+ tsk::make_task(
+ fibonacci_fn,
+ 10),
+ pool) );
+ BOOST_CHECK_EQUAL( h1.get(), 5);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+ BOOST_CHECK_NO_THROW( h1.swap( h2) );
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 5);
+ }
+
+ // check runs in pool
+ void test_case_6()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
> pool( tsk::poolsize( 1) );
tsk::handle< bool > h(
tsk::async(
@@ -69,30 +131,8 @@
BOOST_CHECK_EQUAL( h.get(), true);
}
- // executed twice
-// void test_case_4()
-// {
-// tsk::static_pool<
-// tsk::unbounded_channel< tsk::fifo >
-// > pool( tsk::poolsize( 1) );
-// tsk::task< int > t(
-// tsk::make_task(
-// fibonacci_fn,
-// 10) );
-// tsk::handle< int > h1(
-// tsk::async(
-// pool,
-// t) );
-// BOOST_CHECK_EQUAL( h1.get(), 55);
-// BOOST_CHECK_THROW(
-// tsk::async(
-// pool,
-// t),
-// tsk::task_already_executed);
-// }
-
// check shutdown
- void test_case_5()
+ void test_case_7()
{
tsk::static_pool<
tsk::unbounded_channel< tsk::fifo >
@@ -109,7 +149,7 @@
}
// check runtime_error throw inside task
- void test_case_6()
+ void test_case_8()
{
tsk::static_pool<
tsk::unbounded_channel< tsk::fifo >
@@ -123,7 +163,7 @@
}
// check shutdown with task_rejected exception
- void test_case_7()
+ void test_case_9()
{
tsk::static_pool<
tsk::unbounded_channel< tsk::fifo >
@@ -141,7 +181,7 @@
}
// check shutdown_now with thread_interrupted exception
- void test_case_8()
+ void test_case_10()
{
tsk::static_pool<
tsk::unbounded_channel< tsk::fifo >
@@ -163,7 +203,7 @@
}
// check pending
- void test_case_9()
+ void test_case_11()
{
typedef tsk::static_pool<
tsk::unbounded_channel< tsk::fifo >
@@ -201,42 +241,215 @@
BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
}
- // check interruptation
- void test_case_10()
+ // check wait
+ void test_case_12()
{
- typedef tsk::static_pool<
+ tsk::static_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(
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< int > h(
tsk::async(
tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
+ fibonacci_fn,
10),
pool) );
- tsk::async(
- tsk::make_task(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0),
- pool);
+ h.wait();
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+ }
+
+ // check wait_for
+ void test_case_13()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 1) ),
+ pool) );
+ BOOST_CHECK( h.wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_for
+ void test_case_14()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ),
+ pool) );
+ BOOST_CHECK( ! h.wait_for( pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_until
+ void test_case_15()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 1) ),
+ pool) );
+ BOOST_CHECK( h.wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check wait_until
+ void test_case_16()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ),
+ pool) );
+ BOOST_CHECK( ! h.wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+ }
+
+ // check interrupt
+ void test_case_17()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ delay_fn,
+ pt::seconds( 3) ),
+ pool) );
h.interrupt();
- b.wait();
- pool.shutdown();
- BOOST_CHECK_EQUAL( buffer[0], 0);
- BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+ }
+
+ // check interrupt_and_wait
+ void test_case_18()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ pool) );
+ h.interrupt_and_wait();
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
}
+ // check interrupt_and_wait_for
+ void test_case_19()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ pool) );
+ BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+ }
+
+ // check interrupt_and_wait_for
+ void test_case_20()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ non_interrupt_fn,
+ 3),
+ pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+ }
+
+ // check interrupt_and_wait_until
+ void test_case_21()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) ),
+ pool) );
+ BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 3) ) );
+ BOOST_CHECK( finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( h.has_exception() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+ }
+
+ // check interrupt_and_wait_until
+ void test_case_22()
+ {
+ tsk::static_pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ tsk::handle< void > h(
+ tsk::async(
+ tsk::make_task(
+ non_interrupt_fn,
+ 3),
+ pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+ }
+
// check fifo scheduling
- void test_case_11()
+ void test_case_23()
{
typedef tsk::static_pool<
tsk::unbounded_channel< tsk::fifo >
@@ -270,7 +483,7 @@
}
// check priority scheduling
- void test_case_12()
+ void test_case_24()
{
typedef tsk::static_pool<
tsk::unbounded_channel< tsk::priority< int > >
@@ -309,7 +522,7 @@
}
// check smart scheduling
- void test_case_13()
+ void test_case_25()
{
typedef tsk::static_pool<
tsk::unbounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
@@ -362,7 +575,7 @@
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_1, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_2, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_3, instance) );
-// test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_4, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_5, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_6, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_7, instance) );
@@ -372,6 +585,18 @@
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_11, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_12, instance) );
test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_13, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_14, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_15, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_16, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_17, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_18, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_19, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_20, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_21, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_22, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_23, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_24, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_pool::test_case_25, 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