|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56852 - in sandbox/task: boost boost/task libs/task/src libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2009-10-14 17:39:15
Author: olli
Date: 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
New Revision: 56852
URL: http://svn.boost.org/trac/boost/changeset/56852
Log:
- spin_lock renamed to spin_qunique_lock
- spin_unique_lock conforms to lockable concept
- spin_mutex has spin_unique_lock as typedef -> spin_mutex::scoped_lock
- tests for spin_mutex, spin_condition, spin_unique_lock
Added:
sandbox/task/boost/task/spin_unique_lock.hpp (contents, props changed)
sandbox/task/libs/task/test/test_spin_condition.cpp (contents, props changed)
sandbox/task/libs/task/test/test_spin_mutex.cpp (contents, props changed)
sandbox/task/libs/task/test/test_spin_unique_lock.cpp (contents, props changed)
Removed:
sandbox/task/boost/task/spin_lock.hpp
Text files modified:
sandbox/task/boost/task.hpp | 2
sandbox/task/boost/task/bounded_buffer.hpp | 30
sandbox/task/boost/task/spin_condition.hpp | 4
sandbox/task/boost/task/spin_mutex.hpp | 4
sandbox/task/boost/task/unbounded_buffer.hpp | 16
sandbox/task/libs/task/src/spin_condition.cpp | 9
sandbox/task/libs/task/test/Jamfile.v2 | 3
sandbox/task/libs/task/test/test_as_sub_task.cpp | 55 -
sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp | 1108 ++++++++++++++++++++--------------------
sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp | 950 +++++++++++++++++-----------------
sandbox/task/libs/task/test/test_new_thread.cpp | 470 ++++++++--------
sandbox/task/libs/task/test/test_own_thread.cpp | 522 +++++++++---------
sandbox/task/libs/task/test/test_semaphore.cpp | 232 ++++----
sandbox/task/libs/task/test/test_spin_auto_reset_event.cpp | 296 +++++-----
sandbox/task/libs/task/test/test_spin_count_down_event.cpp | 156 ++--
sandbox/task/libs/task/test/test_spin_manual_reset_event.cpp | 362 ++++++------
sandbox/task/libs/task/test/test_task.cpp | 128 ++--
sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp | 956 +++++++++++++++++-----------------
sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp | 814 ++++++++++++++--------------
19 files changed, 3053 insertions(+), 3064 deletions(-)
Modified: sandbox/task/boost/task.hpp
==============================================================================
--- sandbox/task/boost/task.hpp (original)
+++ sandbox/task/boost/task.hpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -29,9 +29,9 @@
#include <boost/task/spin_auto_reset_event.hpp>
#include <boost/task/spin_condition.hpp>
#include <boost/task/spin_count_down_event.hpp>
-#include <boost/task/spin_lock.hpp>
#include <boost/task/spin_manual_reset_event.hpp>
#include <boost/task/spin_mutex.hpp>
+#include <boost/task/spin_unique_lock.hpp>
#include <boost/task/stacksize.hpp>
#include <boost/task/static_pool.hpp>
#include <boost/task/task.hpp>
Modified: sandbox/task/boost/task/bounded_buffer.hpp
==============================================================================
--- sandbox/task/boost/task/bounded_buffer.hpp (original)
+++ sandbox/task/boost/task/bounded_buffer.hpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -20,7 +20,7 @@
#include <boost/task/exceptions.hpp>
#include <boost/task/semaphore.hpp>
#include <boost/task/spin_condition.hpp>
-#include <boost/task/spin_lock.hpp>
+#include <boost/task/spin_unique_lock.hpp>
#include <boost/task/spin_mutex.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -82,7 +82,7 @@
void put_(
value_type const& va,
- spin_lock< spin_mutex > & lk)
+ spin_unique_lock< spin_mutex > & lk)
{
if ( full_() )
{
@@ -102,7 +102,7 @@
void put_(
value_type const& va,
TimeDuration const& rel_time,
- spin_lock< spin_mutex > & lk)
+ spin_unique_lock< spin_mutex > & lk)
{
if ( full_() )
{
@@ -122,7 +122,7 @@
bool take_(
optional< value_type > & va,
- spin_lock< spin_mutex > & lk)
+ spin_unique_lock< spin_mutex > & lk)
{
bool empty = empty_();
if ( ! active_() && empty)
@@ -160,7 +160,7 @@
bool take_(
optional< value_type > & va,
TimeDuration const& rel_time,
- spin_lock< spin_mutex > & lk)
+ spin_unique_lock< spin_mutex > & lk)
{
bool empty = empty_();
if ( ! active_() && empty)
@@ -240,37 +240,37 @@
bool empty()
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return empty_();
}
std::size_t upper_bound()
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return hwm_;
}
void upper_bound( std::size_t hwm)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
upper_bound_( hwm);
}
std::size_t lower_bound()
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return lwm_;
}
void lower_bound( std::size_t lwm)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
lower_bound_( lwm);
}
void put( value_type const& va)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
put_( va);
}
@@ -279,13 +279,13 @@
value_type const& va,
TimeDuration const& rel_time)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
put_( va, rel_time, lk);
}
bool take( optional< value_type > & va)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return take_( va, lk);
}
@@ -294,13 +294,13 @@
optional< value_type > & va,
TimeDuration const& rel_time)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return take_( va, rel_time, lk);
}
bool try_take( optional< value_type > & va)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return try_take_( va);
}
};
Modified: sandbox/task/boost/task/spin_condition.hpp
==============================================================================
--- sandbox/task/boost/task/spin_condition.hpp (original)
+++ sandbox/task/boost/task/spin_condition.hpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -71,7 +71,7 @@
{
if ( abs_time.is_infinity() )
{
- wait_( lk);
+ wait( lk);
return true;
}
@@ -88,7 +88,7 @@
{
if ( abs_time.is_infinity() )
{
- wait_( lk, pred);
+ wait( lk, pred);
return true;
}
Deleted: sandbox/task/boost/task/spin_lock.hpp
==============================================================================
--- sandbox/task/boost/task/spin_lock.hpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
+++ (empty file)
@@ -1,115 +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)
-//
-// based on boost::interprocess::sync::scoped_lock
-
-#ifndef BOOST_TASK_SPIN_LOCK_H
-#define BOOST_TASK_SPIN_LOCK_H
-
-#include <algorithm>
-
-#include <boost/thread/thread_time.hpp>
-
-#include <boost/task/exceptions.hpp>
-
-namespace boost {
-namespace task {
-
-template< typename Mutex >
-class spin_lock
-{
-private:
- typedef spin_lock< Mutex > lock_t;
- typedef bool spin_lock::*unspecified_bool_type;
-
- Mutex * mtx_;
- bool locked_;
-
- spin_lock( spin_lock &);
- spin_lock & operator=( spin_lock &);
-
-public:
- explicit spin_lock( Mutex & mtx)
- : mtx_( & mtx), locked_( false)
- {
- mtx_->lock();
- locked_ = true;
- }
-
- spin_lock( Mutex & mtx, system_time const& abs_time)
- : mtx_( & mtx), locked_( mtx_->timed_lock( abs_time) )
- {}
-
- template< typename TimeDuration >
- spin_lock( Mutex & mtx, TimeDuration const& rel_time)
- : mtx_( & mtx), locked_( mtx_->timed_lock( rel_time) )
- {}
-
- ~spin_lock()
- {
- try
- { if ( locked_ && mtx_) mtx_->unlock(); }
- catch (...) {}
- }
-
- void lock()
- {
- if ( ! mtx_ || locked_)
- throw lock_error();
- mtx_->lock();
- locked_ = true;
- }
-
- bool try_lock()
- {
- if ( ! mtx_ || locked_)
- throw lock_error();
- locked_ = mtx_->try_lock();
- return locked_;
- }
-
- bool timed_lock( system_time const& abs_time)
- {
- if ( ! mtx_ || locked_)
- throw lock_error();
- locked_ = mtx_->timed_lock( abs_time);
- return locked_;
- }
-
- template< typename TimeDuration >
- bool timed_lock( TimeDuration const& rel_time)
- { return timed_lock( get_system_time() + rel_time); }
-
- void unlock()
- {
- if ( ! mtx_ || ! locked_)
- throw lock_error();
- mtx_->unlock();
- locked_ = false;
- }
-
- bool owns() const
- { return locked_ && mtx_; }
-
- operator unspecified_bool_type() const
- { return locked_ ? & lock_t::locked_ : 0; }
-
- bool operator!() const
- { return ! locked_; }
-
- Mutex * mutex() const
- { return mtx_; }
-
- void swap( spin_lock & other)
- {
- std::swap( mtx_, other.mtx_);
- std::swap( locked_, other.locked_);
- }
-};
-
-}}
-
-#endif // BOOST_TASK_SPIN_LOCK_H
Modified: sandbox/task/boost/task/spin_mutex.hpp
==============================================================================
--- sandbox/task/boost/task/spin_mutex.hpp (original)
+++ sandbox/task/boost/task/spin_mutex.hpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -13,6 +13,8 @@
#include <boost/thread/thread_time.hpp>
#include <boost/utility.hpp>
+#include <boost/task/spin_unique_lock.hpp>
+
namespace boost {
namespace task {
@@ -22,6 +24,8 @@
volatile uint32_t state_;
public:
+ typedef spin_unique_lock< spin_mutex > scoped_lock;
+
spin_mutex();
void lock();
Added: sandbox/task/boost/task/spin_unique_lock.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/spin_unique_lock.hpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -0,0 +1,147 @@
+
+// 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)
+//
+// based on boost::interprocess::sync::scoped_lock
+
+#ifndef BOOST_TASK_SPIN_UNIQUE_LOCK_H
+#define BOOST_TASK_SPIN_UNIQUE_LOCK_H
+
+#include <algorithm>
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/thread_time.hpp>
+
+#include <boost/task/exceptions.hpp>
+
+namespace boost {
+namespace task {
+
+template< typename Mutex >
+class spin_unique_lock
+{
+private:
+ typedef spin_unique_lock< Mutex > lock_t;
+ typedef bool spin_unique_lock::*unspecified_bool_type;
+
+ Mutex * mtx_;
+ bool locked_;
+
+ spin_unique_lock( spin_unique_lock &);
+ spin_unique_lock & operator=( spin_unique_lock &);
+
+public:
+ spin_unique_lock() :
+ mtx_( 0),
+ locked_( false)
+ {}
+
+ explicit spin_unique_lock( Mutex & mtx) :
+ mtx_( & mtx),
+ locked_( false)
+ {
+ mtx_->lock();
+ locked_ = true;
+ }
+
+ spin_unique_lock( Mutex & mtx, adopt_lock_t) :
+ mtx_( & mtx),
+ locked_( true)
+ {}
+
+ spin_unique_lock( Mutex & mtx, defer_lock_t) :
+ mtx_( & mtx),
+ locked_( false)
+ {}
+
+ spin_unique_lock( Mutex & mtx, try_to_lock_t) :
+ mtx_( & mtx),
+ locked_( mtx_->try_lock() )
+ {}
+
+ spin_unique_lock( Mutex & mtx, system_time const& abs_time) :
+ mtx_( & mtx),
+ locked_( mtx_->timed_lock( abs_time) )
+ {}
+
+ template< typename TimeDuration >
+ spin_unique_lock( Mutex & mtx, TimeDuration const& rel_time) :
+ mtx_( & mtx),
+ locked_( mtx_->timed_lock( rel_time) )
+ {}
+
+ ~spin_unique_lock()
+ {
+ try
+ { if ( locked_ && mtx_) mtx_->unlock(); }
+ catch (...) {}
+ }
+
+ void lock()
+ {
+ if ( ! mtx_ || locked_)
+ throw lock_error();
+ mtx_->lock();
+ locked_ = true;
+ }
+
+ bool try_lock()
+ {
+ if ( ! mtx_ || locked_)
+ throw lock_error();
+ locked_ = mtx_->try_lock();
+ return locked_;
+ }
+
+ bool timed_lock( system_time const& abs_time)
+ {
+ if ( ! mtx_ || locked_)
+ throw lock_error();
+ locked_ = mtx_->timed_lock( abs_time);
+ return locked_;
+ }
+
+ template< typename TimeDuration >
+ bool timed_lock( TimeDuration const& rel_time)
+ { return timed_lock( get_system_time() + rel_time); }
+
+ void unlock()
+ {
+ if ( ! mtx_ || ! locked_)
+ throw lock_error();
+ mtx_->unlock();
+ locked_ = false;
+ }
+
+ bool owns_lock() const
+ { return locked_ && mtx_; }
+
+ operator unspecified_bool_type() const
+ { return locked_ ? & lock_t::locked_ : 0; }
+
+ bool operator!() const
+ { return ! locked_; }
+
+ Mutex * mutex() const
+ { return mtx_; }
+
+ Mutex * release()
+ {
+ Mutex * mtx = mtx_;
+ mtx_ = 0;
+ locked_ = false;
+ return mtx;
+ }
+
+ void swap( spin_unique_lock & other)
+ {
+ std::swap( mtx_, other.mtx_);
+ std::swap( locked_, other.locked_);
+ }
+};
+
+}}
+
+#endif // BOOST_TASK_SPIN_UNIQUE_LOCK_H
Modified: sandbox/task/boost/task/unbounded_buffer.hpp
==============================================================================
--- sandbox/task/boost/task/unbounded_buffer.hpp (original)
+++ sandbox/task/boost/task/unbounded_buffer.hpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -19,7 +19,7 @@
#include <boost/task/exceptions.hpp>
#include <boost/task/semaphore.hpp>
#include <boost/task/spin_condition.hpp>
-#include <boost/task/spin_lock.hpp>
+#include <boost/task/spin_unique_lock.hpp>
#include <boost/task/spin_mutex.hpp>
#include <boost/config/abi_prefix.hpp>
@@ -62,7 +62,7 @@
bool take_(
optional< value_type > & va,
- spin_lock< spin_mutex > & lk)
+ spin_unique_lock< spin_mutex > & lk)
{
bool empty = empty_();
if ( ! active_() && empty)
@@ -91,7 +91,7 @@
bool take_(
optional< value_type > & va,
Duration const& rel_time,
- spin_lock< spin_mutex > & lk)
+ spin_unique_lock< spin_mutex > & lk)
{
bool empty = empty_();
if ( ! active_() && empty)
@@ -147,19 +147,19 @@
bool empty()
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return empty_();
}
void put( value_type const& va)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
put_( va);
}
bool take( optional< value_type > & va)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return take_( va, lk);
}
@@ -168,13 +168,13 @@
optional< value_type > & va,
TimeDuration const& rel_time)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return take_( va, rel_time, lk);
}
bool try_take( optional< value_type > & va)
{
- spin_lock< spin_mutex > lk( mtx_);
+ spin_unique_lock< spin_mutex > lk( mtx_);
return try_take_( va);
}
};
Modified: sandbox/task/libs/task/src/spin_condition.cpp
==============================================================================
--- sandbox/task/libs/task/src/spin_condition.cpp (original)
+++ sandbox/task/libs/task/src/spin_condition.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -11,7 +11,6 @@
#include <boost/task/detail/atomic.hpp>
#include <boost/task/spin_mutex.hpp>
-#include <boost/task/spin_lock.hpp>
#include <boost/task/utility.hpp>
namespace boost {
@@ -45,7 +44,7 @@
spin_condition::wait_( spin_mutex & mtx)
{
{
- spin_lock< spin_mutex > lk( enter_mtx_);
+ spin_mutex::scoped_lock lk( enter_mtx_);
BOOST_ASSERT( lk);
detail::atomic_fetch_add( & waiters_, 1);
mtx.unlock();
@@ -64,7 +63,7 @@
this_thread::interruption_point();
}
- spin_lock< spin_mutex > lk( check_mtx_);
+ spin_mutex::scoped_lock lk( check_mtx_);
BOOST_ASSERT( lk);
uint32_t expected = static_cast< uint32_t >( NOTIFY_ONE);
@@ -105,7 +104,7 @@
if ( get_system_time() >= abs_time) return false;
{
- spin_lock< spin_mutex > lk( enter_mtx_, abs_time);
+ spin_mutex::scoped_lock lk( enter_mtx_, abs_time);
BOOST_ASSERT( lk);
detail::atomic_fetch_add( & waiters_, 1);
mtx.unlock();
@@ -140,7 +139,7 @@
}
else
{
- spin_lock< spin_mutex > lk( check_mtx_);
+ spin_mutex::scoped_lock lk( check_mtx_);
BOOST_ASSERT( lk);
uint32_t expected = static_cast< uint32_t >( NOTIFY_ONE);
Modified: sandbox/task/libs/task/test/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/test/Jamfile.v2 (original)
+++ sandbox/task/libs/task/test/Jamfile.v2 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -35,6 +35,9 @@
[ task-test test_bounded_onelock_pool ]
[ task-test test_as_sub_task ]
[ task-test test_semaphore ]
+ [ task-test test_spin_mutex ]
+ [ task-test test_spin_unique_lock ]
+ [ task-test test_spin_condition ]
[ task-test test_spin_count_down_event ]
[ task-test test_spin_auto_reset_event ]
[ task-test test_spin_manual_reset_event ]
Modified: sandbox/task/libs/task/test/test_as_sub_task.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_as_sub_task.cpp (original)
+++ sandbox/task/libs/task/test/test_as_sub_task.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -25,8 +25,8 @@
namespace pt = boost::posix_time;
namespace tsk = boost::task;
-namespace
-{
+namespace {
+
bool exec_sub_task()
{
tsk::handle< bool > h(
@@ -35,41 +35,36 @@
tsk::as_sub_task() ) );
return h.get();
}
+
+void test_runs_not_in_pool()
+{
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), tsk::as_sub_task() ) );
+ BOOST_CHECK_EQUAL( h.get(), false);
}
-class test_as_sub_task
+void test_runs_in_pool()
{
-public:
- // check runs not in pool
- void test_case_1()
- {
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), tsk::as_sub_task() ) );
- BOOST_CHECK_EQUAL( h.get(), false);
- }
-
- // check runs in pool
- void test_case_2()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::handle< bool > h(
- tsk::async(
- tsk::make_task( exec_sub_task),
- pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
- }
-};
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::handle< bool > h(
+ tsk::async(
+ tsk::make_task( exec_sub_task),
+ pool) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+}
+
+}
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::unit_test_framework::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: as-sub-task test suite");
- boost::shared_ptr< test_as_sub_task > instance( new test_as_sub_task() );
- test->add( BOOST_CLASS_TEST_CASE( & test_as_sub_task::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_as_sub_task::test_case_2, instance) );
+ test->add( BOOST_TEST_CASE( & test_runs_in_pool) );
+ test->add( BOOST_TEST_CASE( & test_runs_not_in_pool) );
return test;
}
Modified: sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_bounded_onelock_pool.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -27,565 +27,565 @@
namespace pt = boost::posix_time;
namespace tsk = boost::task;
-class test_bounded_onelock_pool
+namespace {
+
+// check size and move op
+void test_case_1()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool1(
+ tsk::poolsize( 3),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 5) );
+ BOOST_CHECK( pool1);
+ BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool1.upper_bound(), std::size_t( 10) );
+ BOOST_CHECK_EQUAL( pool1.lower_bound(), std::size_t( 5) );
+
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool2;
+ BOOST_CHECK( ! pool2);
+ BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool2.upper_bound(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool2.lower_bound(), tsk::pool_moved);
+
+ pool2 = boost::move( pool1);
+
+ BOOST_CHECK( ! pool1);
+ BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool1.upper_bound(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool1.lower_bound(), tsk::pool_moved);
+
+ BOOST_CHECK( pool2);
+ BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool2.upper_bound(), std::size_t( 10) );
+ BOOST_CHECK_EQUAL( pool2.lower_bound(), std::size_t( 5) );
+
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool2) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check submit
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check assignment
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t), pool) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
+
+// check swap
+void test_case_4()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t1( fibonacci_fn, 5);
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< int > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), 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_5()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+}
+
+// check shutdown
+void test_case_6()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check runtime_error throw inside task
+void test_case_7()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( throwing_fn);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK_THROW( h.get(), std::runtime_error);
+}
+
+// check shutdown with task_rejected exception
+void test_case_8()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_THROW(
+ tsk::async( boost::move( t), pool),
+ tsk::task_rejected);
+}
+
+// check shutdown_now with thread_interrupted exception
+void test_case_9()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::millisec( 500) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ 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( 0) );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check wait
+void test_case_10()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), 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_11()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_12()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_13()
{
-public:
- // check size and move op
- void test_case_1()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool1(
- tsk::poolsize( 3),
- tsk::high_watermark( 10),
- tsk::low_watermark( 5) );
- BOOST_CHECK( pool1);
- BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool1.upper_bound(), std::size_t( 10) );
- BOOST_CHECK_EQUAL( pool1.lower_bound(), std::size_t( 5) );
-
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool2;
- BOOST_CHECK( ! pool2);
- BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool2.upper_bound(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool2.lower_bound(), tsk::pool_moved);
-
- pool2 = boost::move( pool1);
-
- BOOST_CHECK( ! pool1);
- BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool1.upper_bound(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool1.lower_bound(), tsk::pool_moved);
-
- BOOST_CHECK( pool2);
- BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool2.upper_bound(), std::size_t( 10) );
- BOOST_CHECK_EQUAL( pool2.lower_bound(), std::size_t( 5) );
-
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool2) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check submit
- void test_case_2()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check assignment
- void test_case_3()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), pool) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
-
- // check swap
- void test_case_4()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), 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_5()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
- }
-
- // check shutdown
- void test_case_6()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runtime_error throw inside task
- void test_case_7()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
- }
-
- // check shutdown with task_rejected exception
- void test_case_8()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_THROW(
- tsk::async( boost::move( t), pool),
- tsk::task_rejected);
- }
-
- // check shutdown_now with thread_interrupted exception
- void test_case_9()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::millisec( 500) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- 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( 0) );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
-
- // check wait
- void test_case_10()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), 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_11()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_12()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_13()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_14()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_15()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
-
- // check interrupt_all_worker
- void test_case_16()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< void > t2( delay_fn, pt::seconds( 3) );
- tsk::task< void > t3( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< void > h2(
- tsk::async( boost::move( t2), pool) );
- tsk::handle< void > h3(
- tsk::async( boost::move( t3), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- pool.interrupt_all_worker();
- BOOST_CHECK( ! h1.interruption_requested() );
- BOOST_CHECK( ! h2.interruption_requested() );
- BOOST_CHECK( ! h3.interruption_requested() );
- BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
- }
-
- // check interrupt_and_wait
- void test_case_17()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_18()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_19()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
- }
-
- // check interrupt_and_wait_until
- void test_case_20()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_21()
- {
- tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- }
-
- // check fifo scheduling
- void test_case_22()
- {
- typedef tsk::static_pool<
- tsk::bounded_onelock_fifo
- > pool_type;
- BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), pool);
- tsk::async( boost::move( t3), pool);
- 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 priority scheduling
- void test_case_23()
- {
- typedef tsk::static_pool<
- tsk::bounded_onelock_prio_queue< int >
- > pool_type;
- BOOST_CHECK( tsk::has_attribute< pool_type >::value);
- typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
- BOOST_CHECK( type::value);
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), 0, pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), 1, pool);
- tsk::async( boost::move( t3), 0, pool);
- 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 smart scheduling
- void test_case_24()
- {
- typedef tsk::static_pool<
- tsk::bounded_onelock_smart_queue< int, std::less< int > >
- > pool_type;
- BOOST_CHECK( tsk::has_attribute< pool_type >::value);
- typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
- BOOST_CHECK( type::value);
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1(
- barrier_fn,
- boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::task< void > t4(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 1);
- pool.submit( boost::move( t1), 0);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), 2, pool);
- tsk::async( boost::move( t3), 1, pool);
- tsk::async( boost::move( t4), 2, pool);
- 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) );
- }
-};
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_14()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_15()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_all_worker
+void test_case_16()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t1( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t2( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t3( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< void > h2(
+ tsk::async( boost::move( t2), pool) );
+ tsk::handle< void > h3(
+ tsk::async( boost::move( t3), pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ pool.interrupt_all_worker();
+ BOOST_CHECK( ! h1.interruption_requested() );
+ BOOST_CHECK( ! h2.interruption_requested() );
+ BOOST_CHECK( ! h3.interruption_requested() );
+ BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
+}
+
+// check interrupt_and_wait
+void test_case_17()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_18()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_19()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+}
+
+// check interrupt_and_wait_until
+void test_case_20()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_21()
+{
+ tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+}
+
+// check fifo scheduling
+void test_case_22()
+{
+ typedef tsk::static_pool<
+ tsk::bounded_onelock_fifo
+ > pool_type;
+ BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::async( boost::move( t1), pool);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), pool);
+ tsk::async( boost::move( t3), pool);
+ 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 priority scheduling
+void test_case_23()
+{
+ typedef tsk::static_pool<
+ tsk::bounded_onelock_prio_queue< int >
+ > pool_type;
+ BOOST_CHECK( tsk::has_attribute< pool_type >::value);
+ typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
+ BOOST_CHECK( type::value);
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::async( boost::move( t1), 0, pool);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), 1, pool);
+ tsk::async( boost::move( t3), 0, pool);
+ 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 smart scheduling
+void test_case_24()
+{
+ typedef tsk::static_pool<
+ tsk::bounded_onelock_smart_queue< int, std::less< int > >
+ > pool_type;
+ BOOST_CHECK( tsk::has_attribute< pool_type >::value);
+ typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
+ BOOST_CHECK( type::value);
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1(
+ barrier_fn,
+ boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::task< void > t4(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 1);
+ pool.submit( boost::move( t1), 0);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), 2, pool);
+ tsk::async( boost::move( t3), 1, pool);
+ tsk::async( boost::move( t4), 2, pool);
+ 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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: bounded-onelock-pool test suite");
- boost::shared_ptr< test_bounded_onelock_pool > instance( new test_bounded_onelock_pool() );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_6, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_7, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_8, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_9, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_10, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_11, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_12, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_13, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_14, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_15, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_16, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_17, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_18, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_19, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_20, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_21, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_22, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_23, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_onelock_pool::test_case_24, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
+ test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
+ test->add( BOOST_TEST_CASE( & test_case_8) );
+ test->add( BOOST_TEST_CASE( & test_case_9) );
+ test->add( BOOST_TEST_CASE( & test_case_10) );
+ test->add( BOOST_TEST_CASE( & test_case_11) );
+ test->add( BOOST_TEST_CASE( & test_case_12) );
+ test->add( BOOST_TEST_CASE( & test_case_13) );
+ test->add( BOOST_TEST_CASE( & test_case_14) );
+ test->add( BOOST_TEST_CASE( & test_case_15) );
+ test->add( BOOST_TEST_CASE( & test_case_16) );
+ test->add( BOOST_TEST_CASE( & test_case_17) );
+ test->add( BOOST_TEST_CASE( & test_case_18) );
+ test->add( BOOST_TEST_CASE( & test_case_19) );
+ test->add( BOOST_TEST_CASE( & test_case_20) );
+ test->add( BOOST_TEST_CASE( & test_case_21) );
+ test->add( BOOST_TEST_CASE( & test_case_22) );
+ test->add( BOOST_TEST_CASE( & test_case_23) );
+ test->add( BOOST_TEST_CASE( & test_case_24) );
return test;
}
Modified: sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_bounded_twolock_pool.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -27,486 +27,486 @@
namespace pt = boost::posix_time;
namespace tsk = boost::task;
-class test_bounded_twolock_pool
+namespace {
+
+// check size and move op
+void test_case_1()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool1(
+ tsk::poolsize( 3),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 5) );
+ BOOST_CHECK( pool1);
+ BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool1.upper_bound(), std::size_t( 10) );
+ BOOST_CHECK_EQUAL( pool1.lower_bound(), std::size_t( 5) );
+
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool2;
+ BOOST_CHECK( ! pool2);
+ BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool2.upper_bound(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool2.lower_bound(), tsk::pool_moved);
+
+ pool2 = boost::move( pool1);
+
+ BOOST_CHECK( ! pool1);
+ BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool1.upper_bound(), tsk::pool_moved);
+ BOOST_CHECK_THROW( pool1.lower_bound(), tsk::pool_moved);
+
+ BOOST_CHECK( pool2);
+ BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool2.upper_bound(), std::size_t( 10) );
+ BOOST_CHECK_EQUAL( pool2.lower_bound(), std::size_t( 5) );
+
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool2) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check submit
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check assignment
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t), pool) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
+
+// check swap
+void test_case_4()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t1( fibonacci_fn, 5);
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< int > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), 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_5()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+}
+
+// check shutdown
+void test_case_6()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check runtime_error throw inside task
+void test_case_7()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( throwing_fn);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK_THROW( h.get(), std::runtime_error);
+}
+
+// check shutdown with task_rejected exception
+void test_case_8()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_THROW(
+ tsk::async( boost::move( t), pool),
+ tsk::task_rejected);
+}
+
+// check shutdown_now with thread_interrupted exception
+void test_case_9()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::millisec( 500) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ 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( 0) );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check wait
+void test_case_10()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), 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_11()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_12()
{
-public:
- // check size and move op
- void test_case_1()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool1(
- tsk::poolsize( 3),
- tsk::high_watermark( 10),
- tsk::low_watermark( 5) );
- BOOST_CHECK( pool1);
- BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool1.upper_bound(), std::size_t( 10) );
- BOOST_CHECK_EQUAL( pool1.lower_bound(), std::size_t( 5) );
-
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool2;
- BOOST_CHECK( ! pool2);
- BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool2.upper_bound(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool2.lower_bound(), tsk::pool_moved);
-
- pool2 = boost::move( pool1);
-
- BOOST_CHECK( ! pool1);
- BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool1.upper_bound(), tsk::pool_moved);
- BOOST_CHECK_THROW( pool1.lower_bound(), tsk::pool_moved);
-
- BOOST_CHECK( pool2);
- BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
- BOOST_CHECK_EQUAL( pool2.upper_bound(), std::size_t( 10) );
- BOOST_CHECK_EQUAL( pool2.lower_bound(), std::size_t( 5) );
-
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool2) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check submit
- void test_case_2()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check assignment
- void test_case_3()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), pool) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
-
- // check swap
- void test_case_4()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), 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_5()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
- }
-
- // check shutdown
- void test_case_6()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runtime_error throw inside task
- void test_case_7()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
- }
-
- // check shutdown with task_rejected exception
- void test_case_8()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< int > t( fibonacci_fn, 10);
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_THROW(
- tsk::async( boost::move( t), pool),
- tsk::task_rejected);
- }
-
- // check shutdown_now with thread_interrupted exception
- void test_case_9()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::millisec( 500) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- 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( 0) );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
-
- // check wait
- void test_case_10()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), 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_11()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_12()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_13()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_14()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 1),
- tsk::low_watermark( 1) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_15()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
-
- // check interrupt_all_worker
- void test_case_16()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< void > t2( delay_fn, pt::seconds( 3) );
- tsk::task< void > t3( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< void > h2(
- tsk::async( boost::move( t2), pool) );
- tsk::handle< void > h3(
- tsk::async( boost::move( t3), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- pool.interrupt_all_worker();
- BOOST_CHECK( ! h1.interruption_requested() );
- BOOST_CHECK( ! h2.interruption_requested() );
- BOOST_CHECK( ! h3.interruption_requested() );
- BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
- }
-
- // check interrupt_and_wait
- void test_case_17()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_18()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_19()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
- }
-
- // check interrupt_and_wait_until
- void test_case_20()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_21()
- {
- tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool(
- tsk::poolsize( 5),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- }
-
- // check fifo scheduling
- void test_case_22()
- {
- typedef tsk::static_pool<
- tsk::bounded_twolock_fifo
- > pool_type;
- BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
- pool_type pool(
- tsk::poolsize( 1),
- tsk::high_watermark( 10),
- tsk::low_watermark( 10) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), pool);
- tsk::async( boost::move( t3), pool);
- 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) );
- }
-};
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_13()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_14()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_15()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_all_worker
+void test_case_16()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t1( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t2( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t3( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< void > h2(
+ tsk::async( boost::move( t2), pool) );
+ tsk::handle< void > h3(
+ tsk::async( boost::move( t3), pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ pool.interrupt_all_worker();
+ BOOST_CHECK( ! h1.interruption_requested() );
+ BOOST_CHECK( ! h2.interruption_requested() );
+ BOOST_CHECK( ! h3.interruption_requested() );
+ BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
+}
+
+// check interrupt_and_wait
+void test_case_17()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_18()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t( interrupt_fn, pt::seconds( 1), boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_19()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+}
+
+// check interrupt_and_wait_until
+void test_case_20()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_21()
+{
+ tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool(
+ tsk::poolsize( 5),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+}
+
+// check fifo scheduling
+void test_case_22()
+{
+ typedef tsk::static_pool<
+ tsk::bounded_twolock_fifo
+ > pool_type;
+ BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::async( boost::move( t1), pool);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), pool);
+ tsk::async( boost::move( t3), pool);
+ 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) );
+}
+
+}
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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: bounded-twolock-pool test suite");
- boost::shared_ptr< test_bounded_twolock_pool > instance( new test_bounded_twolock_pool() );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_6, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_7, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_8, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_9, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_10, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_11, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_12, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_13, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_14, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_15, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_16, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_17, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_18, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_19, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_20, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_21, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_bounded_twolock_pool::test_case_22, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
+ test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
+ test->add( BOOST_TEST_CASE( & test_case_8) );
+ test->add( BOOST_TEST_CASE( & test_case_9) );
+ test->add( BOOST_TEST_CASE( & test_case_10) );
+ test->add( BOOST_TEST_CASE( & test_case_11) );
+ test->add( BOOST_TEST_CASE( & test_case_12) );
+ test->add( BOOST_TEST_CASE( & test_case_13) );
+ test->add( BOOST_TEST_CASE( & test_case_14) );
+ test->add( BOOST_TEST_CASE( & test_case_15) );
+ test->add( BOOST_TEST_CASE( & test_case_16) );
+ test->add( BOOST_TEST_CASE( & test_case_17) );
+ test->add( BOOST_TEST_CASE( & test_case_18) );
+ test->add( BOOST_TEST_CASE( & test_case_19) );
+ test->add( BOOST_TEST_CASE( & test_case_20) );
+ test->add( BOOST_TEST_CASE( & test_case_21) );
+ test->add( BOOST_TEST_CASE( & test_case_22) );
return test;
}
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-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -25,265 +25,265 @@
namespace pt = boost::posix_time;
namespace tsk = boost::task;
-class test_new_thread
+namespace {
+
+// check assignment
+void test_case_1()
{
-public:
- // check assignment
- void test_case_1()
- {
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), tsk::new_thread() ) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t), tsk::new_thread() ) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
- // check swap
- void test_case_2()
- {
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), tsk::new_thread() ) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), 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 swap
+void test_case_2()
+{
+ tsk::task< int > t1( fibonacci_fn, 5);
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< int > h1(
+ tsk::async( boost::move( t1), tsk::new_thread() ) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), 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_3()
- {
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), tsk::new_thread() ) );
- BOOST_CHECK_EQUAL( h.get(), false);
- }
+// check runs not in pool
+void test_case_3()
+{
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), tsk::new_thread() ) );
+ BOOST_CHECK_EQUAL( h.get(), false);
+}
- // check runtime_error throw inside task
- void test_case_4()
- {
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), tsk::new_thread() ) );
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
- }
+// check runtime_error throw inside task
+void test_case_4()
+{
+ tsk::task< void > t( throwing_fn);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), tsk::new_thread() ) );
+ BOOST_CHECK_THROW( h.get(), std::runtime_error);
+}
- // check wait
- void test_case_5()
- {
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), 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
+void test_case_5()
+{
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), 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_6()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_6()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_7()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_7()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_8()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_8()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_9()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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 wait_for
+void test_case_9()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_10()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), tsk::new_thread() ) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
+// check interrupt
+void test_case_10()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), tsk::new_thread() ) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
- // check interrupt_and_wait
- void test_case_11()
- {
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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
+void test_case_11()
+{
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_12()
- {
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_12()
+{
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_13()
- {
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), tsk::new_thread() ) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
- }
+// check interrupt_and_wait_for
+void test_case_13()
+{
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), tsk::new_thread() ) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+}
- // check interrupt_and_wait_until
- void test_case_14()
- {
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_14()
+{
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_15()
+{
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), tsk::new_thread() ) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+}
- // check interrupt_and_wait_until
- void test_case_15()
+// check waitfor_all()
+void test_case_16()
+{
+ std::vector< tsk::handle< int > > vec;
+ for ( int i = 0; i <= 5; ++i)
{
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
+ tsk::task< int > t( fibonacci_fn, i);
+ vec.push_back(
tsk::async( boost::move( t), tsk::new_thread() ) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
}
+ tsk::waitfor_all( vec.begin(), vec.end() );
+ BOOST_CHECK( vec[0].is_ready() );
+ BOOST_CHECK( vec[1].is_ready() );
+ BOOST_CHECK( vec[2].is_ready() );
+ BOOST_CHECK( vec[3].is_ready() );
+ BOOST_CHECK( vec[4].is_ready() );
+ BOOST_CHECK( vec[5].is_ready() );
+ BOOST_CHECK_EQUAL( vec[0].get(), 0);
+ BOOST_CHECK_EQUAL( vec[1].get(), 1);
+ BOOST_CHECK_EQUAL( vec[2].get(), 1);
+ BOOST_CHECK_EQUAL( vec[3].get(), 2);
+ BOOST_CHECK_EQUAL( vec[4].get(), 3);
+ BOOST_CHECK_EQUAL( vec[5].get(), 5);
+}
- // check waitfor_all()
- void test_case_16()
- {
- std::vector< tsk::handle< int > > vec;
- for ( int i = 0; i <= 5; ++i)
- {
- tsk::task< int > t( fibonacci_fn, i);
- vec.push_back(
- tsk::async( boost::move( t), tsk::new_thread() ) );
- }
- tsk::waitfor_all( vec.begin(), vec.end() );
- BOOST_CHECK( vec[0].is_ready() );
- BOOST_CHECK( vec[1].is_ready() );
- BOOST_CHECK( vec[2].is_ready() );
- BOOST_CHECK( vec[3].is_ready() );
- BOOST_CHECK( vec[4].is_ready() );
- BOOST_CHECK( vec[5].is_ready() );
- BOOST_CHECK_EQUAL( vec[0].get(), 0);
- BOOST_CHECK_EQUAL( vec[1].get(), 1);
- BOOST_CHECK_EQUAL( vec[2].get(), 1);
- BOOST_CHECK_EQUAL( vec[3].get(), 2);
- BOOST_CHECK_EQUAL( vec[4].get(), 3);
- BOOST_CHECK_EQUAL( vec[5].get(), 5);
- }
+// check waitfor_any()
+void test_case_17()
+{
+ tsk::task< void > t1( delay_fn, pt::seconds( 3) );
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< void > h1(
+ tsk::async( boost::move( t1), tsk::new_thread() ) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), tsk::new_thread() ) );
+ tsk::waitfor_any( h1, h2);
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
- // check waitfor_any()
- void test_case_17()
- {
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), tsk::new_thread() ) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), tsk::new_thread() ) );
- tsk::waitfor_any( h1, h2);
- BOOST_CHECK( ! h1.is_ready() );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
-};
+}
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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: new-thread test suite");
- 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_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_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
+ test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
+ test->add( BOOST_TEST_CASE( & test_case_8) );
+ test->add( BOOST_TEST_CASE( & test_case_9) );
+ test->add( BOOST_TEST_CASE( & test_case_10) );
+ test->add( BOOST_TEST_CASE( & test_case_11) );
+ test->add( BOOST_TEST_CASE( & test_case_12) );
+ test->add( BOOST_TEST_CASE( & test_case_13) );
+ test->add( BOOST_TEST_CASE( & test_case_14) );
+ test->add( BOOST_TEST_CASE( & test_case_15) );
+ test->add( BOOST_TEST_CASE( & test_case_16) );
+ test->add( BOOST_TEST_CASE( & test_case_17) );
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-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -25,293 +25,293 @@
namespace pt = boost::posix_time;
namespace tsk = boost::task;
-class test_own_thread
+namespace {
+
+// check assignment
+void test_case_1()
{
-public:
- // check assignment
- void test_case_1()
- {
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), tsk::own_thread() ) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t), tsk::own_thread() ) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
- // check swap
- void test_case_2()
- {
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), tsk::own_thread() ) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), 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 swap
+void test_case_2()
+{
+ tsk::task< int > t1( fibonacci_fn, 5);
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< int > h1(
+ tsk::async( boost::move( t1), tsk::own_thread() ) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), 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_3()
- {
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), tsk::own_thread() ) );
- BOOST_CHECK_EQUAL( h.get(), false);
- }
+// check runs not in pool
+void test_case_3()
+{
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), tsk::own_thread() ) );
+ BOOST_CHECK_EQUAL( h.get(), false);
+}
- // check runtime_error throw inside task
- void test_case_4()
- {
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), tsk::own_thread() ) );
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
- }
+// check runtime_error throw inside task
+void test_case_4()
+{
+ tsk::task< void > t( throwing_fn);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), tsk::own_thread() ) );
+ BOOST_CHECK_THROW( h.get(), std::runtime_error);
+}
- // check task_uninitialized
- void test_case_5()
- {
- tsk::handle< int > h;
- BOOST_CHECK_THROW( h.get(), tsk::task_uninitialized);
- BOOST_CHECK_THROW( h.wait(), tsk::task_uninitialized);
- BOOST_CHECK_THROW( h.wait_for( pt::seconds( 1) ), tsk::task_uninitialized);
- BOOST_CHECK_THROW(
- h.wait_until( boost::get_system_time() + pt::seconds( 1) ),
- tsk::task_uninitialized);
- BOOST_CHECK( ! h.is_ready() );
- BOOST_CHECK( ! h.has_value() );
- BOOST_CHECK( ! h.has_exception() );
- }
+// check task_uninitialized
+void test_case_5()
+{
+ tsk::handle< int > h;
+ BOOST_CHECK_THROW( h.get(), tsk::task_uninitialized);
+ BOOST_CHECK_THROW( h.wait(), tsk::task_uninitialized);
+ BOOST_CHECK_THROW( h.wait_for( pt::seconds( 1) ), tsk::task_uninitialized);
+ BOOST_CHECK_THROW(
+ h.wait_until( boost::get_system_time() + pt::seconds( 1) ),
+ tsk::task_uninitialized);
+ BOOST_CHECK( ! h.is_ready() );
+ BOOST_CHECK( ! h.has_value() );
+ BOOST_CHECK( ! h.has_exception() );
+}
- // check wait
- void test_case_6()
- {
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), 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
+void test_case_6()
+{
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), 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_7()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_7()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_8()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 2) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_8()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 2) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_9()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_9()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_10()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 2) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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 wait_for
+void test_case_10()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 2) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_11()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), tsk::own_thread() ) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_NO_THROW( h.get() );
- }
+// check interrupt
+void test_case_11()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), tsk::own_thread() ) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_NO_THROW( h.get() );
+}
- // check interrupt_and_wait
- void test_case_12()
- {
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 3),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), tsk::own_thread() ) );
- h.interrupt_and_wait();
- BOOST_CHECK( ! finished);
- BOOST_CHECK( h.is_ready() );
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_NO_THROW( h.get() );
- }
+// check interrupt_and_wait
+void test_case_12()
+{
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 3),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), tsk::own_thread() ) );
+ h.interrupt_and_wait();
+ BOOST_CHECK( ! finished);
+ BOOST_CHECK( h.is_ready() );
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_NO_THROW( h.get() );
+}
- // check interrupt_and_wait_for
- void test_case_13()
- {
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_13()
+{
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_14()
- {
- tsk::task< void > t( non_interrupt_fn, 2);
- tsk::handle< void > h(
- tsk::async( boost::move( t), tsk::own_thread() ) );
- BOOST_CHECK( h.interrupt_and_wait_for( pt::seconds( 1) ) );
- BOOST_CHECK_NO_THROW( h.get() );
- }
+// check interrupt_and_wait_for
+void test_case_14()
+{
+ tsk::task< void > t( non_interrupt_fn, 2);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_15()
- {
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_15()
+{
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_16()
+// check interrupt_and_wait_until
+void test_case_16()
+{
+ tsk::task< void > t( non_interrupt_fn, 2);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_17()
+{
+ std::vector< tsk::handle< int > > vec;
+ for ( int i = 0; i <= 5; ++i)
{
- tsk::task< void > t( non_interrupt_fn, 2);
- tsk::handle< void > h(
+ tsk::task< int > t( fibonacci_fn, i);
+ vec.push_back(
tsk::async( boost::move( t), tsk::own_thread() ) );
- BOOST_CHECK( h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- BOOST_CHECK_NO_THROW( h.get() );
}
+ tsk::waitfor_all( vec.begin(), vec.end() );
+ BOOST_CHECK( vec[0].is_ready() );
+ BOOST_CHECK( vec[1].is_ready() );
+ BOOST_CHECK( vec[2].is_ready() );
+ BOOST_CHECK( vec[3].is_ready() );
+ BOOST_CHECK( vec[4].is_ready() );
+ BOOST_CHECK( vec[5].is_ready() );
+ BOOST_CHECK_EQUAL( vec[0].get(), 0);
+ BOOST_CHECK_EQUAL( vec[1].get(), 1);
+ BOOST_CHECK_EQUAL( vec[2].get(), 1);
+ BOOST_CHECK_EQUAL( vec[3].get(), 2);
+ BOOST_CHECK_EQUAL( vec[4].get(), 3);
+ BOOST_CHECK_EQUAL( vec[5].get(), 5);
+}
- // check waitfor_all()
- void test_case_17()
- {
- std::vector< tsk::handle< int > > vec;
- for ( int i = 0; i <= 5; ++i)
- {
- tsk::task< int > t( fibonacci_fn, i);
- vec.push_back(
- tsk::async( boost::move( t), tsk::own_thread() ) );
- }
- tsk::waitfor_all( vec.begin(), vec.end() );
- BOOST_CHECK( vec[0].is_ready() );
- BOOST_CHECK( vec[1].is_ready() );
- BOOST_CHECK( vec[2].is_ready() );
- BOOST_CHECK( vec[3].is_ready() );
- BOOST_CHECK( vec[4].is_ready() );
- BOOST_CHECK( vec[5].is_ready() );
- BOOST_CHECK_EQUAL( vec[0].get(), 0);
- BOOST_CHECK_EQUAL( vec[1].get(), 1);
- BOOST_CHECK_EQUAL( vec[2].get(), 1);
- BOOST_CHECK_EQUAL( vec[3].get(), 2);
- BOOST_CHECK_EQUAL( vec[4].get(), 3);
- BOOST_CHECK_EQUAL( vec[5].get(), 5);
- }
+// check waitfor_any()
+void test_case_18()
+{
+ tsk::task< void > t1( delay_fn, pt::seconds( 3) );
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< void > h1(
+ tsk::async( boost::move( t1), tsk::own_thread() ) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), tsk::own_thread() ) );
+ tsk::waitfor_any( h1, h2);
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
- // check waitfor_any()
- void test_case_18()
- {
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), tsk::own_thread() ) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), tsk::own_thread() ) );
- tsk::waitfor_any( h1, h2);
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
+// check interrupt + wait
+void test_case_19()
+{
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), tsk::own_thread() ) );
+ h.interrupt();
+ BOOST_CHECK_NO_THROW( h.wait() );
+ BOOST_CHECK_NO_THROW( h.get() );
+}
- // check interrupt + wait
- void test_case_19()
- {
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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* [])
{
- boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.Task: test suite") );
+ boost::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: own-thread test suite");
- 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_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_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
+ test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
+ test->add( BOOST_TEST_CASE( & test_case_8) );
+ test->add( BOOST_TEST_CASE( & test_case_9) );
+ test->add( BOOST_TEST_CASE( & test_case_10) );
+ test->add( BOOST_TEST_CASE( & test_case_11) );
+ test->add( BOOST_TEST_CASE( & test_case_12) );
+ test->add( BOOST_TEST_CASE( & test_case_13) );
+ test->add( BOOST_TEST_CASE( & test_case_14) );
+ test->add( BOOST_TEST_CASE( & test_case_15) );
+ test->add( BOOST_TEST_CASE( & test_case_16) );
+ test->add( BOOST_TEST_CASE( & test_case_17) );
+ test->add( BOOST_TEST_CASE( & test_case_18) );
+ test->add( BOOST_TEST_CASE( & test_case_19) );
return test;
}
Modified: sandbox/task/libs/task/test/test_semaphore.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_semaphore.cpp (original)
+++ sandbox/task/libs/task/test/test_semaphore.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -33,152 +33,152 @@
}
}
-class test_semaphore
+namespace {
+
+// check wait in new thread
+void test_case_1()
{
-public:
- // check wait in new thread
- void test_case_1()
+ uint32_t n = 3;
+ tsk::semaphore sem( 0);
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( sem) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( sem) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( ! h2.is_ready() );
+
+ sem.post();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() || h2.is_ready() );
+ if ( h1.is_ready() )
{
- uint32_t n = 3;
- tsk::semaphore sem( 0);
+ BOOST_CHECK_EQUAL( h1.get(), n);
+ BOOST_CHECK( ! h2.is_ready() );
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- tsk::new_thread() ) );
+ sem.post();
boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
+ }
+ else
+ {
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
BOOST_CHECK( ! h1.is_ready() );
- BOOST_CHECK( ! h2.is_ready() );
sem.post();
boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() || h2.is_ready() );
- if ( h1.is_ready() )
- {
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK( ! h2.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- }
- else
- {
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- BOOST_CHECK( ! h1.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
-
- }
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
+
}
+}
- // check wait in pool
- void test_case_2()
+// check wait in pool
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+
+ uint32_t n = 3;
+ tsk::semaphore sem( 0);
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( sem) ),
+ pool) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( sem) ),
+ pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( ! h2.is_ready() );
+
+ sem.post();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() || h2.is_ready() );
+ if ( h1.is_ready() )
{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
-
- uint32_t n = 3;
- tsk::semaphore sem( 0);
-
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- pool) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
BOOST_CHECK( ! h2.is_ready() );
sem.post();
boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() || h2.is_ready() );
- if ( h1.is_ready() )
- {
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK( ! h2.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- }
- else
- {
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- BOOST_CHECK( ! h1.is_ready() );
-
- sem.post();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
-
- }
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
}
-
- void test_case_3()
+ else
{
- uint32_t n = 3;
- tsk::semaphore sem( 2);
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
+ BOOST_CHECK( ! h1.is_ready() );
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( sem) ),
- tsk::new_thread() ) );
+ sem.post();
boost::this_thread::sleep( pt::millisec( 250) );
BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK( h2.is_ready() );
BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK_EQUAL( h2.get(), n);
+
}
-};
+}
+
+void test_case_3()
+{
+ uint32_t n = 3;
+ tsk::semaphore sem( 2);
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( sem) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( sem) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
+ BOOST_CHECK_EQUAL( h2.get(), n);
+}
+
+}
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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: semaphore test suite");
- boost::shared_ptr< test_semaphore > instance( new test_semaphore() );
- test->add( BOOST_CLASS_TEST_CASE( & test_semaphore::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_semaphore::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_semaphore::test_case_3, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
return test;
}
Modified: sandbox/task/libs/task/test/test_spin_auto_reset_event.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_auto_reset_event.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_auto_reset_event.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -20,186 +20,182 @@
#include <boost/task.hpp>
-#include "test_functions.hpp"
-
namespace pt = boost::posix_time;
namespace tsk = boost::task;
namespace {
+
uint32_t wait_fn( uint32_t n, tsk::spin_auto_reset_event & ev)
{
ev.wait();
return n;
}
-}
-class test_spin_auto_reset_event
+// check wait in new thread
+void test_case_1()
{
-public:
- // check wait in new thread
- void test_case_1()
- {
- uint32_t n = 3;
- tsk::spin_auto_reset_event ev;
-
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
+ uint32_t n = 3;
+ tsk::spin_auto_reset_event ev;
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( ! h2.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() || h2.is_ready() );
+ if ( h1.is_ready() )
+ {
+ BOOST_CHECK_EQUAL( h1.get(), n);
+ BOOST_CHECK( ! h2.is_ready() );
+
+ ev.set();
boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
+ }
+ else
+ {
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
BOOST_CHECK( ! h1.is_ready() );
- BOOST_CHECK( ! h2.is_ready() );
ev.set();
boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() || h2.is_ready() );
- if ( h1.is_ready() )
- {
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK( ! h2.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- }
- else
- {
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- BOOST_CHECK( ! h1.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
-
- }
- }
-
- // check wait in pool
- void test_case_2()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
-
- uint32_t n = 3;
- tsk::spin_auto_reset_event ev;
-
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- pool) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- pool) );
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
+
+ }
+}
+
+// check wait in pool
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+
+ uint32_t n = 3;
+ tsk::spin_auto_reset_event ev;
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ pool) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( ! h2.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() || h2.is_ready() );
+ if ( h1.is_ready() )
+ {
+ BOOST_CHECK_EQUAL( h1.get(), n);
+ BOOST_CHECK( ! h2.is_ready() );
+
+ ev.set();
+
boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
+ }
+ else
+ {
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
BOOST_CHECK( ! h1.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
+
+ }
+}
+
+void test_case_3()
+{
+ uint32_t n = 3;
+ tsk::spin_auto_reset_event ev( true);
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() || h2.is_ready() );
+ if ( h1.is_ready() )
+ {
+ BOOST_CHECK_EQUAL( h1.get(), n);
BOOST_CHECK( ! h2.is_ready() );
ev.set();
boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() || h2.is_ready() );
- if ( h1.is_ready() )
- {
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK( ! h2.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- }
- else
- {
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- BOOST_CHECK( ! h1.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
-
- }
- }
-
- void test_case_3()
- {
- uint32_t n = 3;
- tsk::spin_auto_reset_event ev( true);
-
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() || h2.is_ready() );
- if ( h1.is_ready() )
- {
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK( ! h2.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- }
- else
- {
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h2.get(), n);
- BOOST_CHECK( ! h1.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
-
- }
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
}
-};
+ else
+ {
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h2.get(), n);
+ BOOST_CHECK( ! h1.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
+
+ }
+}
+
+}
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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: spin-auto-reset-event test suite");
- boost::shared_ptr< test_spin_auto_reset_event > instance( new test_spin_auto_reset_event() );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_auto_reset_event::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_auto_reset_event::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_auto_reset_event::test_case_3, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
return test;
}
Added: sandbox/task/libs/task/test/test_spin_condition.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_spin_condition.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -0,0 +1,201 @@
+
+// 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)
+//
+// This test is based on the tests of Boost.Thread
+
+#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/utility.hpp>
+
+#include <boost/task.hpp>
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+namespace {
+
+struct condition_test
+{
+ condition_test() :
+ notified( 0),
+ awoken( 0)
+ {}
+
+ tsk::spin_mutex mtx;
+ tsk::spin_condition condition;
+ int notified;
+ int awoken;
+};
+
+struct cond_predicate
+{
+ cond_predicate( int & var_, int val_) :
+ var( var_),
+ val( val_)
+ {}
+
+ bool operator()()
+ { return var == val; }
+
+ int & var;
+ int val;
+
+private:
+ void operator=( cond_predicate&);
+};
+
+void condition_test_thread( condition_test * data)
+{
+ tsk::spin_mutex::scoped_lock lk( data->mtx);
+ BOOST_CHECK( lk);
+ while ( ! ( data->notified > 0) )
+ data->condition.wait( lk);
+ BOOST_CHECK( lk);
+ data->awoken++;
+}
+
+void condition_test_waits( condition_test * data)
+{
+ tsk::spin_mutex::scoped_lock lk( data->mtx);
+ BOOST_CHECK( lk);
+
+ // Test wait.
+ while ( data->notified != 1)
+ data->condition.wait( lk);
+ BOOST_CHECK( lk);
+ BOOST_CHECK_EQUAL( data->notified, 1);
+ data->awoken++;
+ data->condition.notify_one();
+
+ // Test predicate wait.
+ data->condition.wait( lk, cond_predicate( data->notified, 2));
+ BOOST_CHECK( lk);
+ BOOST_CHECK_EQUAL( data->notified, 2);
+ data->awoken++;
+ data->condition.notify_one();
+
+ // Test timed_wait.
+ pt::millisec xt( 250);
+ while ( data->notified != 3)
+ data->condition.timed_wait( lk, xt);
+ BOOST_CHECK( lk);
+ BOOST_CHECK_EQUAL( data->notified, 3);
+ data->awoken++;
+ data->condition.notify_one();
+
+ // Test predicate timed_wait.
+ cond_predicate pred( data->notified, 4);
+ BOOST_CHECK( data->condition.timed_wait( lk, xt, pred));
+ BOOST_CHECK( lk);
+ BOOST_CHECK( pred() );
+ BOOST_CHECK_EQUAL( data->notified, 4);
+ data->awoken++;
+ data->condition.notify_one();
+
+ // Test predicate timed_wait with relative timeout
+ cond_predicate pred_rel( data->notified, 5);
+ BOOST_CHECK( data->condition.timed_wait( lk, pt::seconds( 10), pred_rel) );
+ BOOST_CHECK( lk);
+ BOOST_CHECK( pred_rel() );
+ BOOST_CHECK_EQUAL( data->notified, 5);
+ data->awoken++;
+ data->condition.notify_one();
+}
+
+void test_wait()
+{
+ condition_test data;
+
+ boost::thread thrd(
+ boost::bind(
+ & condition_test_waits, & data) );
+
+ {
+ tsk::spin_mutex::scoped_lock lk( data.mtx);
+ BOOST_CHECK( lk);
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ data.notified++;
+ data.condition.notify_one();
+ while ( data.awoken != 1)
+ data.condition.wait( lk);
+ BOOST_CHECK( lk);
+ BOOST_CHECK_EQUAL( data.awoken, 1);
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ data.notified++;
+ data.condition.notify_one();
+ while ( data.awoken != 2)
+ data.condition.wait( lk);
+ BOOST_CHECK( lk);
+ BOOST_CHECK_EQUAL( data.awoken, 2);
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ data.notified++;
+ data.condition.notify_one();
+ while ( data.awoken != 3)
+ data.condition.wait( lk);
+ BOOST_CHECK( lk);
+ BOOST_CHECK_EQUAL( data.awoken, 3);
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ data.notified++;
+ data.condition.notify_one();
+ while ( data.awoken != 4)
+ data.condition.wait( lk);
+ BOOST_CHECK( lk);
+ BOOST_CHECK_EQUAL( data.awoken, 4);
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ data.notified++;
+ data.condition.notify_one();
+ while ( data.awoken != 5)
+ data.condition.wait( lk);
+ BOOST_CHECK( lk);
+ BOOST_CHECK_EQUAL( data.awoken, 5);
+ }
+
+ thrd.join();
+ BOOST_CHECK_EQUAL( data.awoken, 5);
+}
+
+
+void test_interruption_point()
+{
+ condition_test data;
+
+ boost::thread thrd(
+ boost::bind(
+ & condition_test_thread, & data) );
+
+ thrd.interrupt();
+ thrd.join();
+
+ BOOST_CHECK_EQUAL( data.awoken, 0);
+}
+
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test_framework::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: spin-condition test suite");
+
+ test->add( BOOST_TEST_CASE( & test_wait) );
+ test->add( BOOST_TEST_CASE( & test_interruption_point) );
+
+ return test;
+}
Modified: sandbox/task/libs/task/test/test_spin_count_down_event.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_count_down_event.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_count_down_event.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -20,110 +20,106 @@
#include <boost/task.hpp>
-#include "test_functions.hpp"
-
namespace pt = boost::posix_time;
namespace tsk = boost::task;
namespace {
+
uint32_t wait_fn( uint32_t n, tsk::spin_count_down_event & ev)
{
ev.wait();
return n;
}
+
+// check initial + current
+void test_case_1()
+{
+ uint32_t n = 3;
+ tsk::spin_count_down_event ev( n);
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), n);
+
+ ev.set();
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 2) );
+
+ ev.set();
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 1) );
+
+ ev.set();
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 0) );
+
+ ev.set();
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 0) );
}
-class test_spin_count_down_event
+// check wait in new thread
+void test_case_2()
{
-public:
- // check initial + current
- void test_case_1()
+ uint32_t n = 3;
+ tsk::spin_count_down_event ev( n);
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), n);
+
+ tsk::handle< uint32_t > h(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+ BOOST_CHECK( ! h.is_ready() );
+ for ( uint32_t i = 0; i < n; ++i)
{
- uint32_t n = 3;
- tsk::spin_count_down_event ev( n);
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), n);
-
- ev.set();
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 2) );
-
- ev.set();
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 1) );
-
- ev.set();
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 0) );
-
ev.set();
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 0) );
- }
-
- // check wait in new thread
- void test_case_2()
- {
- uint32_t n = 3;
- tsk::spin_count_down_event ev( n);
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), n);
-
- tsk::handle< uint32_t > h(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
BOOST_CHECK( ! h.is_ready() );
- for ( uint32_t i = 0; i < n; ++i)
- {
- ev.set();
- BOOST_CHECK( ! h.is_ready() );
- }
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 0) );
- BOOST_CHECK_EQUAL( h.get(), n);
}
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 0) );
+ BOOST_CHECK_EQUAL( h.get(), n);
+}
- // check wait in pool
- void test_case_3()
+// check wait in pool
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+
+ uint32_t n = 3;
+ tsk::spin_count_down_event ev( n);
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), n);
+
+ tsk::handle< uint32_t > h(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ pool) );
+ BOOST_CHECK( ! h.is_ready() );
+ for ( uint32_t i = 0; i < n; ++i)
{
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
-
- uint32_t n = 3;
- tsk::spin_count_down_event ev( n);
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), n);
-
- tsk::handle< uint32_t > h(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- pool) );
+ ev.set();
BOOST_CHECK( ! h.is_ready() );
- for ( uint32_t i = 0; i < n; ++i)
- {
- ev.set();
- BOOST_CHECK( ! h.is_ready() );
- }
- BOOST_CHECK_EQUAL( ev.initial(), n);
- BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 0) );
- BOOST_CHECK_EQUAL( h.get(), n);
}
-};
+ BOOST_CHECK_EQUAL( ev.initial(), n);
+ BOOST_CHECK_EQUAL( ev.current(), static_cast< uint32_t >( 0) );
+ BOOST_CHECK_EQUAL( h.get(), n);
+}
+
+}
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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: spin-count-down-event test suite");
- boost::shared_ptr< test_spin_count_down_event > instance( new test_spin_count_down_event() );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_count_down_event::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_count_down_event::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_count_down_event::test_case_3, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
return test;
}
Modified: sandbox/task/libs/task/test/test_spin_manual_reset_event.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_spin_manual_reset_event.cpp (original)
+++ sandbox/task/libs/task/test/test_spin_manual_reset_event.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -20,205 +20,201 @@
#include <boost/task.hpp>
-#include "test_functions.hpp"
-
namespace pt = boost::posix_time;
namespace tsk = boost::task;
namespace {
+
uint32_t wait_fn( uint32_t n, tsk::spin_manual_reset_event & ev)
{
ev.wait();
return n;
}
+
+// check wait in new thread
+void test_case_1()
+{
+ uint32_t n = 3;
+ tsk::spin_manual_reset_event ev;
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( ! h2.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
+ BOOST_CHECK_EQUAL( h2.get(), n);
+
+ ev.reset();
+
+ tsk::handle< uint32_t > h3(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h4(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h3.is_ready() );
+ BOOST_CHECK( ! h4.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h3.is_ready() );
+ BOOST_CHECK( h4.is_ready() );
+ BOOST_CHECK_EQUAL( h3.get(), n);
+ BOOST_CHECK_EQUAL( h4.get(), n);
+}
+
+// check wait in pool
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+
+ uint32_t n = 3;
+ tsk::spin_manual_reset_event ev;
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ pool) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ pool) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h1.is_ready() );
+ BOOST_CHECK( ! h2.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
+ BOOST_CHECK_EQUAL( h2.get(), n);
+
+ ev.reset();
+
+ tsk::handle< uint32_t > h3(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h4(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h3.is_ready() );
+ BOOST_CHECK( ! h4.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h3.is_ready() );
+ BOOST_CHECK( h4.is_ready() );
+ BOOST_CHECK_EQUAL( h3.get(), n);
+ BOOST_CHECK_EQUAL( h4.get(), n);
}
-class test_spin_manual_reset_event
+void test_case_3()
{
-public:
- // check wait in new thread
- void test_case_1()
- {
- uint32_t n = 3;
- tsk::spin_manual_reset_event ev;
-
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( ! h1.is_ready() );
- BOOST_CHECK( ! h2.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK_EQUAL( h2.get(), n);
-
- ev.reset();
-
- tsk::handle< uint32_t > h3(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h4(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( ! h3.is_ready() );
- BOOST_CHECK( ! h4.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h3.is_ready() );
- BOOST_CHECK( h4.is_ready() );
- BOOST_CHECK_EQUAL( h3.get(), n);
- BOOST_CHECK_EQUAL( h4.get(), n);
- }
-
- // check wait in pool
- void test_case_2()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
-
- uint32_t n = 3;
- tsk::spin_manual_reset_event ev;
-
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- pool) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- pool) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( ! h1.is_ready() );
- BOOST_CHECK( ! h2.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK_EQUAL( h2.get(), n);
-
- ev.reset();
-
- tsk::handle< uint32_t > h3(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h4(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( ! h3.is_ready() );
- BOOST_CHECK( ! h4.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h3.is_ready() );
- BOOST_CHECK( h4.is_ready() );
- BOOST_CHECK_EQUAL( h3.get(), n);
- BOOST_CHECK_EQUAL( h4.get(), n);
- }
-
- void test_case_3()
- {
- uint32_t n = 3;
- tsk::spin_manual_reset_event ev( true);
-
- tsk::handle< uint32_t > h1(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h2(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h1.is_ready() );
- BOOST_CHECK( h2.is_ready() );
- BOOST_CHECK_EQUAL( h1.get(), n);
- BOOST_CHECK_EQUAL( h2.get(), n);
-
- ev.reset();
-
- tsk::handle< uint32_t > h3(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
- tsk::handle< uint32_t > h4(
- tsk::async(
- tsk::make_task(
- wait_fn,
- n, boost::ref( ev) ),
- tsk::new_thread() ) );
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( ! h3.is_ready() );
- BOOST_CHECK( ! h4.is_ready() );
-
- ev.set();
-
- boost::this_thread::sleep( pt::millisec( 250) );
- BOOST_CHECK( h3.is_ready() );
- BOOST_CHECK( h4.is_ready() );
- BOOST_CHECK_EQUAL( h3.get(), n);
- BOOST_CHECK_EQUAL( h4.get(), n);
- }
-};
+ uint32_t n = 3;
+ tsk::spin_manual_reset_event ev( true);
+
+ tsk::handle< uint32_t > h1(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h2(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h1.is_ready() );
+ BOOST_CHECK( h2.is_ready() );
+ BOOST_CHECK_EQUAL( h1.get(), n);
+ BOOST_CHECK_EQUAL( h2.get(), n);
+
+ ev.reset();
+
+ tsk::handle< uint32_t > h3(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+ tsk::handle< uint32_t > h4(
+ tsk::async(
+ tsk::make_task(
+ wait_fn,
+ n, boost::ref( ev) ),
+ tsk::new_thread() ) );
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( ! h3.is_ready() );
+ BOOST_CHECK( ! h4.is_ready() );
+
+ ev.set();
+
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK( h3.is_ready() );
+ BOOST_CHECK( h4.is_ready() );
+ BOOST_CHECK_EQUAL( h3.get(), n);
+ BOOST_CHECK_EQUAL( h4.get(), n);
+}
+
+}
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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: spin-manual-reset-event test suite");
- boost::shared_ptr< test_spin_manual_reset_event > instance( new test_spin_manual_reset_event() );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_manual_reset_event::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_manual_reset_event::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_spin_manual_reset_event::test_case_3, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
return test;
}
Added: sandbox/task/libs/task/test/test_spin_mutex.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_spin_mutex.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -0,0 +1,61 @@
+
+// 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)
+//
+// This test is based on the tests of Boost.Thread
+
+#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/utility.hpp>
+
+#include <boost/task.hpp>
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+namespace {
+
+void test_lock()
+{
+ tsk::spin_mutex mtx;
+ tsk::spin_condition cond;
+
+ {
+ tsk::spin_mutex::scoped_lock lk( mtx);
+ BOOST_CHECK( lk);
+ }
+ tsk::spin_mutex::scoped_lock lk( mtx);
+ BOOST_CHECK( lk);
+
+ BOOST_CHECK( ! cond.timed_wait( lk, pt::millisec( 250) ) );
+ BOOST_CHECK( lk);
+
+ lk.unlock();
+ BOOST_CHECK( ! lk);
+ lk.lock();
+ BOOST_CHECK( lk);
+};
+
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test_framework::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: spin-mutex test suite");
+
+ test->add( BOOST_TEST_CASE( & test_lock) );
+
+ return test;
+}
Added: sandbox/task/libs/task/test/test_spin_unique_lock.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_spin_unique_lock.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -0,0 +1,209 @@
+
+// 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)
+//
+// This test is based on the tests of Boost.Thread
+
+#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/utility.hpp>
+
+#include <boost/task.hpp>
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+namespace {
+
+struct dummy_mutex
+{
+ bool is_locked;
+
+ dummy_mutex() :
+ is_locked( false)
+ {}
+
+ void lock()
+ { is_locked = true; }
+
+ bool try_lock()
+ {
+ if ( is_locked)
+ return false;
+ is_locked = true;
+ return true;
+ }
+
+ void unlock()
+ { is_locked = false; }
+};
+
+void test_lock()
+{
+ tsk::spin_mutex mtx;
+ tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx);
+
+ BOOST_CHECK( lk);
+ BOOST_CHECK( lk.owns_lock() );
+
+ lk.unlock();
+
+ BOOST_CHECK( ! lk);
+ BOOST_CHECK( ! lk.owns_lock() );
+}
+
+void test_defer_lock()
+{
+ tsk::spin_mutex mtx;
+ tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx, boost::defer_lock);
+
+ BOOST_CHECK( ! lk);
+ BOOST_CHECK( ! lk.owns_lock() );
+
+ lk.lock();
+
+ BOOST_CHECK( lk);
+ BOOST_CHECK( lk.owns_lock() );
+}
+
+void test_adopt_lock()
+{
+ tsk::spin_mutex mtx;
+ mtx.lock();
+ tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx, boost::adopt_lock);
+
+ BOOST_CHECK( lk);
+ BOOST_CHECK( lk.owns_lock() );
+}
+
+void test_try_lock()
+{
+ tsk::spin_mutex mtx;
+ tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx, boost::defer_lock);
+
+ BOOST_CHECK( ! lk);
+ BOOST_CHECK( ! lk.owns_lock() );
+
+ lk.try_lock();
+
+ BOOST_CHECK( lk);
+ BOOST_CHECK( lk.owns_lock() );
+}
+
+void test_lock_twice()
+{
+ tsk::spin_mutex mtx;
+ tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx);
+
+ BOOST_CHECK_THROW( lk.lock(), tsk::lock_error);
+}
+
+void test_try_lock_twice()
+{
+ tsk::spin_mutex mtx;
+ tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx);
+
+ BOOST_CHECK_THROW( lk.try_lock(), tsk::lock_error);
+}
+
+void test_unlock_twice()
+{
+ tsk::spin_mutex mtx;
+ tsk::spin_unique_lock< tsk::spin_mutex > lk( mtx);
+ lk.unlock();
+
+ BOOST_CHECK_THROW( lk.unlock(), tsk::lock_error);
+}
+
+void test_default_ctor()
+{
+ tsk::spin_unique_lock< tsk::spin_mutex > lk;
+
+ BOOST_CHECK( ! lk);
+ BOOST_CHECK( ! lk.owns_lock() );
+}
+
+void test_lock_concept()
+{
+ tsk::spin_mutex mtx1, mtx2, mtx3;
+
+ tsk::spin_mutex::scoped_lock lk1( mtx1, boost::defer_lock),
+ lk2( mtx2, boost::defer_lock),
+ lk3( mtx3, boost::defer_lock);
+
+ BOOST_CHECK( ! lk1.owns_lock() );
+ BOOST_CHECK( ! lk2.owns_lock() );
+ BOOST_CHECK( ! lk3.owns_lock() );
+
+ boost::lock( lk1, lk2, lk3);
+
+ BOOST_CHECK( lk1.owns_lock() );
+ BOOST_CHECK( lk2.owns_lock() );
+ BOOST_CHECK( lk3.owns_lock() );
+}
+
+void test_try_lock_concept()
+{
+ dummy_mutex mtx1, mtx2;
+ mtx2.lock();
+
+ tsk::spin_unique_lock< dummy_mutex > lk1( mtx1, boost::defer_lock),
+ lk2( mtx2, boost::defer_lock);
+
+ int res = boost::try_lock( lk1, lk2);
+
+ BOOST_CHECK( res == 1);
+ BOOST_CHECK( ! mtx1.is_locked);
+ BOOST_CHECK( mtx2.is_locked);
+ BOOST_CHECK( ! lk1.owns_lock() );
+ BOOST_CHECK( ! lk2.owns_lock() );
+}
+
+void test_swap()
+{
+ tsk::spin_mutex mtx1, mtx2;
+
+ tsk::spin_unique_lock< tsk::spin_mutex > lk1( mtx1), lk2( mtx2);
+
+ BOOST_CHECK_EQUAL( lk1.mutex(), & mtx1);
+ BOOST_CHECK_EQUAL( lk2.mutex(), & mtx2);
+
+ lk1.swap( lk2);
+
+ BOOST_CHECK_EQUAL( lk1.mutex(), & mtx2);
+ BOOST_CHECK_EQUAL( lk2.mutex(), & mtx1);
+}
+
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test_framework::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: spin-lock test suite");
+
+ test->add( BOOST_TEST_CASE( & test_lock) );
+ test->add( BOOST_TEST_CASE( & test_defer_lock) );
+ test->add( BOOST_TEST_CASE( & test_adopt_lock) );
+ test->add( BOOST_TEST_CASE( & test_try_lock) );
+ test->add( BOOST_TEST_CASE( & test_lock_twice) );
+ test->add( BOOST_TEST_CASE( & test_try_lock_twice) );
+ test->add( BOOST_TEST_CASE( & test_unlock_twice) );
+ test->add( BOOST_TEST_CASE( & test_default_ctor) );
+ test->add( BOOST_TEST_CASE( & test_lock_concept) );
+ test->add( BOOST_TEST_CASE( & test_try_lock_concept) );
+ test->add( BOOST_TEST_CASE( & test_swap) );
+
+ return test;
+}
Modified: sandbox/task/libs/task/test/test_task.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_task.cpp (original)
+++ sandbox/task/libs/task/test/test_task.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -25,79 +25,79 @@
namespace pt = boost::posix_time;
namespace tsk = boost::task;
+namespace {
+
void zero_args_fn() {}
int one_arg_fn( int i) { return i; }
int two_args_fn( int i, std::string const& s) { return i; }
-class test_task
+// check vaild task
+void test_case_1()
+{
+ tsk::task< int > t1( fibonacci_fn, 10);
+ tsk::task< int > t2;
+ BOOST_CHECK( t1);
+ BOOST_CHECK( ! t2);
+}
+
+// check make_task
+void test_case_2()
+{
+ tsk::task< void > t1;
+ BOOST_CHECK( ! t1);
+ t1 = tsk::make_task( zero_args_fn);
+ BOOST_CHECK( t1);
+ tsk::task< int > t2 = tsk::make_task( one_arg_fn, 1);
+ BOOST_CHECK( t2);
+ tsk::task< int > t3;
+ BOOST_CHECK( ! t3);
+ t3 = tsk::make_task( two_args_fn, 1, "abc");
+ BOOST_CHECK( t3);
+}
+
+// check moved task
+void test_case_3()
+{
+ tsk::task< int > t1( fibonacci_fn, 10);
+ BOOST_CHECK( t1);
+ tsk::task< int > t2( boost::move( t1) );
+ BOOST_CHECK( ! t1);
+ BOOST_CHECK_THROW( t1(), tsk::task_moved);
+ BOOST_CHECK_NO_THROW( t2() );
+}
+
+// check execute twice
+void test_case_4()
+{
+ tsk::task< int > t1( fibonacci_fn, 10);
+ BOOST_CHECK_NO_THROW( t1() );
+ BOOST_CHECK_THROW( t1(), tsk::task_already_executed);
+}
+
+// check swap
+void test_case_5()
{
-public:
- // check vaild task
- void test_case_1()
- {
- tsk::task< int > t1( fibonacci_fn, 10);
- tsk::task< int > t2;
- BOOST_CHECK( t1);
- BOOST_CHECK( ! t2);
- }
-
- // check make_task
- void test_case_2()
- {
- tsk::task< void > t1;
- BOOST_CHECK( ! t1);
- t1 = tsk::make_task( zero_args_fn);
- BOOST_CHECK( t1);
- tsk::task< int > t2 = tsk::make_task( one_arg_fn, 1);
- BOOST_CHECK( t2);
- tsk::task< int > t3;
- BOOST_CHECK( ! t3);
- t3 = tsk::make_task( two_args_fn, 1, "abc");
- BOOST_CHECK( t3);
- }
-
- // check moved task
- void test_case_3()
- {
- tsk::task< int > t1( fibonacci_fn, 10);
- BOOST_CHECK( t1);
- tsk::task< int > t2( boost::move( t1) );
- BOOST_CHECK( ! t1);
- BOOST_CHECK_THROW( t1(), tsk::task_moved);
- BOOST_CHECK_NO_THROW( t2() );
- }
-
- // check execute twice
- void test_case_4()
- {
- tsk::task< int > t1( fibonacci_fn, 10);
- BOOST_CHECK_NO_THROW( t1() );
- BOOST_CHECK_THROW( t1(), tsk::task_already_executed);
- }
-
- // check swap
- void test_case_5()
- {
- tsk::task< int > t1( fibonacci_fn, 10);
- tsk::task< int > t2;
- BOOST_CHECK_NO_THROW( t1() );
- BOOST_CHECK_THROW( t2(), tsk::task_moved);
- t1.swap( t2);
- BOOST_CHECK_THROW( t1(), tsk::task_moved);
- BOOST_CHECK_THROW( t2(), tsk::task_already_executed);
- }
-};
+ tsk::task< int > t1( fibonacci_fn, 10);
+ tsk::task< int > t2;
+ BOOST_CHECK_NO_THROW( t1() );
+ BOOST_CHECK_THROW( t2(), tsk::task_moved);
+ t1.swap( t2);
+ BOOST_CHECK_THROW( t1(), tsk::task_moved);
+ BOOST_CHECK_THROW( t2(), tsk::task_already_executed);
+}
+
+}
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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: task test suite");
- boost::shared_ptr< test_task > instance( new test_task() );
- test->add( BOOST_CLASS_TEST_CASE( & test_task::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_task::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_task::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_task::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_task::test_case_5, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
return test;
}
Modified: sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_unbounded_onelock_pool.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -27,489 +27,489 @@
namespace pt = boost::posix_time;
namespace tsk = boost::task;
-class test_unbounded_onelock_pool
+namespace {
+
+// check size and move op
+void test_case_1()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool1( tsk::poolsize( 3) );
+ BOOST_CHECK( pool1);
+ BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
+
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool2;
+ BOOST_CHECK( ! pool2);
+ BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
+
+ pool2 = boost::move( pool1);
+
+ BOOST_CHECK( ! pool1);
+ BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
+
+ BOOST_CHECK( pool2);
+ BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
+
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool2) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check submit
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check assignment
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t), pool) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
+
+// check swap
+void test_case_4()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t1( fibonacci_fn, 5);
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< int > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), 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_5()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+}
+
+// check shutdown
+void test_case_6()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check runtime_error throw inside task
+void test_case_7()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< void > t( throwing_fn);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK_THROW( h.get(), std::runtime_error);
+}
+
+// check shutdown with task_rejected exception
+void test_case_8()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_THROW(
+ tsk::async( boost::move( t), pool),
+ tsk::task_rejected);
+}
+
+// check shutdown_now with thread_interrupted exception
+void test_case_9()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< void > t( delay_fn, pt::millisec( 500) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ 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( 0) );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check wait
+void test_case_10()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), 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_11()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_12()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_13()
{
-public:
- // check size and move op
- void test_case_1()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool1( tsk::poolsize( 3) );
- BOOST_CHECK( pool1);
- BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
-
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool2;
- BOOST_CHECK( ! pool2);
- BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
-
- pool2 = boost::move( pool1);
-
- BOOST_CHECK( ! pool1);
- BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
-
- BOOST_CHECK( pool2);
- BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
-
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool2) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check submit
- void test_case_2()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check assignment
- void test_case_3()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), pool) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
-
- // check swap
- void test_case_4()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), 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_5()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
- }
-
- // check shutdown
- void test_case_6()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runtime_error throw inside task
- void test_case_7()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
- }
-
- // check shutdown with task_rejected exception
- void test_case_8()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_THROW(
- tsk::async( boost::move( t), pool),
- tsk::task_rejected);
- }
-
- // check shutdown_now with thread_interrupted exception
- void test_case_9()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< void > t( delay_fn, pt::millisec( 500) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- 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( 0) );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
-
- // check wait
- void test_case_10()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), 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_11()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_12()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_13()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_14()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_15()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
-
- // check interrupt_all_worker
- void test_case_16()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 5) );
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< void > t2( delay_fn, pt::seconds( 3) );
- tsk::task< void > t3( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< void > h2(
- tsk::async( boost::move( t2), pool) );
- tsk::handle< void > h3(
- tsk::async( boost::move( t3), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- pool.interrupt_all_worker();
- BOOST_CHECK( ! h1.interruption_requested() );
- BOOST_CHECK( ! h2.interruption_requested() );
- BOOST_CHECK( ! h3.interruption_requested() );
- BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
- }
-
- // check interrupt_and_wait
- void test_case_17()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_18()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_19()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
- }
-
- // check interrupt_and_wait_until
- void test_case_20()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_21()
- {
- tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- }
-
- // check fifo scheduling
- void test_case_22()
- {
- typedef tsk::static_pool<
- tsk::unbounded_onelock_fifo
- > pool_type;
- BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), pool);
- tsk::async( boost::move( t3), pool);
- 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 priority scheduling
- void test_case_23()
- {
- typedef tsk::static_pool<
- tsk::unbounded_onelock_prio_queue< int >
- > pool_type;
- BOOST_CHECK( tsk::has_attribute< pool_type >::value);
- typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
- BOOST_CHECK( type::value);
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10) ;
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), 0, pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), 1, pool);
- tsk::async( boost::move( t3), 0, pool);
- 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 smart scheduling
- void test_case_24()
- {
- typedef tsk::static_pool<
- tsk::unbounded_onelock_smart_queue< int, std::less< int > >
- > pool_type;
- BOOST_CHECK( tsk::has_attribute< pool_type >::value);
- typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
- BOOST_CHECK( type::value);
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::task< void > t4(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 1);
- pool.submit( boost::move( t1), 0);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), 2, pool);
- tsk::async( boost::move( t3), 1, pool);
- tsk::async( boost::move( t4), 2, pool);
- 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) );
- }
-};
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_14()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_15()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_all_worker
+void test_case_16()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 5) );
+ tsk::task< void > t1( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t2( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t3( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< void > h2(
+ tsk::async( boost::move( t2), pool) );
+ tsk::handle< void > h3(
+ tsk::async( boost::move( t3), pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ pool.interrupt_all_worker();
+ BOOST_CHECK( ! h1.interruption_requested() );
+ BOOST_CHECK( ! h2.interruption_requested() );
+ BOOST_CHECK( ! h3.interruption_requested() );
+ BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
+}
+
+// check interrupt_and_wait
+void test_case_17()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_18()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_19()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+}
+
+// check interrupt_and_wait_until
+void test_case_20()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_21()
+{
+ tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+}
+
+// check fifo scheduling
+void test_case_22()
+{
+ typedef tsk::static_pool<
+ tsk::unbounded_onelock_fifo
+ > pool_type;
+ BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::async( boost::move( t1), pool);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), pool);
+ tsk::async( boost::move( t3), pool);
+ 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 priority scheduling
+void test_case_23()
+{
+ typedef tsk::static_pool<
+ tsk::unbounded_onelock_prio_queue< int >
+ > pool_type;
+ BOOST_CHECK( tsk::has_attribute< pool_type >::value);
+ typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
+ BOOST_CHECK( type::value);
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) ;
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::async( boost::move( t1), 0, pool);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), 1, pool);
+ tsk::async( boost::move( t3), 0, pool);
+ 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 smart scheduling
+void test_case_24()
+{
+ typedef tsk::static_pool<
+ tsk::unbounded_onelock_smart_queue< int, std::less< int > >
+ > pool_type;
+ BOOST_CHECK( tsk::has_attribute< pool_type >::value);
+ typedef boost::is_same< tsk::attribute_type< pool_type >::type, int > type;
+ BOOST_CHECK( type::value);
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::task< void > t4(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 1);
+ pool.submit( boost::move( t1), 0);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), 2, pool);
+ tsk::async( boost::move( t3), 1, pool);
+ tsk::async( boost::move( t4), 2, pool);
+ 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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: unbounded-onelock-pool test suite");
- boost::shared_ptr< test_unbounded_onelock_pool > instance( new test_unbounded_onelock_pool() );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_6, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_7, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_8, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_9, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_10, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_11, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_12, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_13, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_14, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_15, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_16, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_17, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_18, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_19, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_20, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_21, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_22, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_23, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_onelock_pool::test_case_24, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
+ test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
+ test->add( BOOST_TEST_CASE( & test_case_8) );
+ test->add( BOOST_TEST_CASE( & test_case_9) );
+ test->add( BOOST_TEST_CASE( & test_case_10) );
+ test->add( BOOST_TEST_CASE( & test_case_11) );
+ test->add( BOOST_TEST_CASE( & test_case_12) );
+ test->add( BOOST_TEST_CASE( & test_case_13) );
+ test->add( BOOST_TEST_CASE( & test_case_14) );
+ test->add( BOOST_TEST_CASE( & test_case_15) );
+ test->add( BOOST_TEST_CASE( & test_case_16) );
+ test->add( BOOST_TEST_CASE( & test_case_17) );
+ test->add( BOOST_TEST_CASE( & test_case_18) );
+ test->add( BOOST_TEST_CASE( & test_case_19) );
+ test->add( BOOST_TEST_CASE( & test_case_20) );
+ test->add( BOOST_TEST_CASE( & test_case_21) );
+ test->add( BOOST_TEST_CASE( & test_case_22) );
+ test->add( BOOST_TEST_CASE( & test_case_23) );
+ test->add( BOOST_TEST_CASE( & test_case_24) );
return test;
}
Modified: sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp (original)
+++ sandbox/task/libs/task/test/test_unbounded_twolock_pool.cpp 2009-10-14 17:39:12 EDT (Wed, 14 Oct 2009)
@@ -27,418 +27,418 @@
namespace pt = boost::posix_time;
namespace tsk = boost::task;
-class test_unbounded_twolock_pool
+namespace {
+
+// check size and move op
+void test_case_1()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool1( tsk::poolsize( 3) );
+ BOOST_CHECK( pool1);
+ BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
+
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool2;
+ BOOST_CHECK( ! pool2);
+ BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
+
+ pool2 = boost::move( pool1);
+
+ BOOST_CHECK( ! pool1);
+ BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
+
+ BOOST_CHECK( pool2);
+ BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
+
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool2) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check submit
+void test_case_2()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check assignment
+void test_case_3()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h1;
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t), pool) );
+ h1 = h2;
+ BOOST_CHECK_EQUAL( h1.get(), 55);
+ BOOST_CHECK_EQUAL( h2.get(), 55);
+}
+
+// check swap
+void test_case_4()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t1( fibonacci_fn, 5);
+ tsk::task< int > t2( fibonacci_fn, 10);
+ tsk::handle< int > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< int > h2(
+ tsk::async( boost::move( t2), 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_5()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< bool > t( runs_in_pool_fn);
+ tsk::handle< bool > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK_EQUAL( h.get(), true);
+}
+
+// check shutdown
+void test_case_6()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( h.get(), 55);
+}
+
+// check runtime_error throw inside task
+void test_case_7()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< void > t( throwing_fn);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ pool.shutdown();
+ BOOST_CHECK_THROW( h.get(), std::runtime_error);
+}
+
+// check shutdown with task_rejected exception
+void test_case_8()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_THROW(
+ tsk::async( boost::move( t), pool),
+ tsk::task_rejected);
+}
+
+// check shutdown_now with thread_interrupted exception
+void test_case_9()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 1) );
+ tsk::task< void > t( delay_fn, pt::millisec( 500) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ 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( 0) );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check wait
+void test_case_10()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< int > t( fibonacci_fn, 10);
+ tsk::handle< int > h(
+ tsk::async( boost::move( t), 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_11()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_12()
{
-public:
- // check size and move op
- void test_case_1()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool1( tsk::poolsize( 3) );
- BOOST_CHECK( pool1);
- BOOST_CHECK_EQUAL( pool1.size(), std::size_t( 3) );
-
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool2;
- BOOST_CHECK( ! pool2);
- BOOST_CHECK_THROW( pool2.size(), tsk::pool_moved);
-
- pool2 = boost::move( pool1);
-
- BOOST_CHECK( ! pool1);
- BOOST_CHECK_THROW( pool1.size(), tsk::pool_moved);
-
- BOOST_CHECK( pool2);
- BOOST_CHECK_EQUAL( pool2.size(), std::size_t( 3) );
-
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool2) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check submit
- void test_case_2()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check assignment
- void test_case_3()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h1;
- tsk::handle< int > h2(
- tsk::async( boost::move( t), pool) );
- h1 = h2;
- BOOST_CHECK_EQUAL( h1.get(), 55);
- BOOST_CHECK_EQUAL( h2.get(), 55);
- }
-
- // check swap
- void test_case_4()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t1( fibonacci_fn, 5);
- tsk::task< int > t2( fibonacci_fn, 10);
- tsk::handle< int > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< int > h2(
- tsk::async( boost::move( t2), 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_5()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< bool > t( runs_in_pool_fn);
- tsk::handle< bool > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK_EQUAL( h.get(), true);
- }
-
- // check shutdown
- void test_case_6()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( h.get(), 55);
- }
-
- // check runtime_error throw inside task
- void test_case_7()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< void > t( throwing_fn);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- pool.shutdown();
- BOOST_CHECK_THROW( h.get(), std::runtime_error);
- }
-
- // check shutdown with task_rejected exception
- void test_case_8()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< int > t( fibonacci_fn, 10);
- pool.shutdown();
- BOOST_CHECK( pool.closed() );
- BOOST_CHECK_THROW(
- tsk::async( boost::move( t), pool),
- tsk::task_rejected);
- }
-
- // check shutdown_now with thread_interrupted exception
- void test_case_9()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 1) );
- tsk::task< void > t( delay_fn, pt::millisec( 500) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- 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( 0) );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
-
- // check wait
- void test_case_10()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< int > t( fibonacci_fn, 10);
- tsk::handle< int > h(
- tsk::async( boost::move( t), 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_11()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_12()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_13()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 1) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_14()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_15()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- h.interrupt();
- BOOST_CHECK( h.interruption_requested() );
- BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
- }
-
- // check interrupt_all_worker
- void test_case_16()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 5) );
- tsk::task< void > t1( delay_fn, pt::seconds( 3) );
- tsk::task< void > t2( delay_fn, pt::seconds( 3) );
- tsk::task< void > t3( delay_fn, pt::seconds( 3) );
- tsk::handle< void > h1(
- tsk::async( boost::move( t1), pool) );
- tsk::handle< void > h2(
- tsk::async( boost::move( t2), pool) );
- tsk::handle< void > h3(
- tsk::async( boost::move( t3), pool) );
- boost::this_thread::sleep( pt::millisec( 250) );
- pool.interrupt_all_worker();
- BOOST_CHECK( ! h1.interruption_requested() );
- BOOST_CHECK( ! h2.interruption_requested() );
- BOOST_CHECK( ! h3.interruption_requested() );
- BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
- BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
- BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
- }
-
- // check interrupt_and_wait
- void test_case_17()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_18()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_19()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
- }
-
- // check interrupt_and_wait_until
- void test_case_20()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- bool finished( false);
- tsk::task< void > t(
- interrupt_fn,
- pt::seconds( 1),
- boost::ref( finished) );
- tsk::handle< void > h(
- tsk::async( boost::move( t), 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_21()
- {
- tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool( tsk::poolsize( 3) );
- tsk::task< void > t( non_interrupt_fn, 3);
- tsk::handle< void > h(
- tsk::async( boost::move( t), pool) );
- BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
- }
-
- // check fifo scheduling
- void test_case_22()
- {
- typedef tsk::static_pool<
- tsk::unbounded_twolock_fifo
- > pool_type;
- BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
- pool_type pool( tsk::poolsize( 1) );
- boost::barrier b( 2);
- std::vector< int > buffer;
- tsk::task< void > t1( barrier_fn, boost::ref( b) );
- tsk::task< void > t2(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 10);
- tsk::task< void > t3(
- buffer_fibonacci_fn,
- boost::ref( buffer),
- 0);
- tsk::async( boost::move( t1), pool);
- boost::this_thread::sleep( pt::millisec( 250) );
- tsk::async( boost::move( t2), pool);
- tsk::async( boost::move( t3), pool);
- 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) );
- }
-};
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_13()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 1) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_14()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_15()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ h.interrupt();
+ BOOST_CHECK( h.interruption_requested() );
+ BOOST_CHECK_THROW( h.get(), tsk::task_interrupted);
+}
+
+// check interrupt_all_worker
+void test_case_16()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 5) );
+ tsk::task< void > t1( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t2( delay_fn, pt::seconds( 3) );
+ tsk::task< void > t3( delay_fn, pt::seconds( 3) );
+ tsk::handle< void > h1(
+ tsk::async( boost::move( t1), pool) );
+ tsk::handle< void > h2(
+ tsk::async( boost::move( t2), pool) );
+ tsk::handle< void > h3(
+ tsk::async( boost::move( t3), pool) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ pool.interrupt_all_worker();
+ BOOST_CHECK( ! h1.interruption_requested() );
+ BOOST_CHECK( ! h2.interruption_requested() );
+ BOOST_CHECK( ! h3.interruption_requested() );
+ BOOST_CHECK_THROW( h1.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h2.get(), tsk::task_interrupted);
+ BOOST_CHECK_THROW( h3.get(), tsk::task_interrupted);
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 5) );
+}
+
+// check interrupt_and_wait
+void test_case_17()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_18()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_19()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_for( pt::seconds( 1) ) );
+}
+
+// check interrupt_and_wait_until
+void test_case_20()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ bool finished( false);
+ tsk::task< void > t(
+ interrupt_fn,
+ pt::seconds( 1),
+ boost::ref( finished) );
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), 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_21()
+{
+ tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool( tsk::poolsize( 3) );
+ tsk::task< void > t( non_interrupt_fn, 3);
+ tsk::handle< void > h(
+ tsk::async( boost::move( t), pool) );
+ BOOST_CHECK( ! h.interrupt_and_wait_until( boost::get_system_time() + pt::seconds( 1) ) );
+}
+
+// check fifo scheduling
+void test_case_22()
+{
+ typedef tsk::static_pool<
+ tsk::unbounded_twolock_fifo
+ > pool_type;
+ BOOST_CHECK( ! tsk::has_attribute< pool_type >::value);
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ std::vector< int > buffer;
+ tsk::task< void > t1( barrier_fn, boost::ref( b) );
+ tsk::task< void > t2(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10);
+ tsk::task< void > t3(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0);
+ tsk::async( boost::move( t1), pool);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ tsk::async( boost::move( t2), pool);
+ tsk::async( boost::move( t3), pool);
+ 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) );
+}
+
+}
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::unit_test::test_suite * test =
+ BOOST_TEST_SUITE("Boost.Task: unbounded-twolock-pool test suite");
- boost::shared_ptr< test_unbounded_twolock_pool > instance( new test_unbounded_twolock_pool() );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_1, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_2, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_3, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_4, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_5, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_6, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_7, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_8, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_9, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_10, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_11, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_12, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_13, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_14, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_15, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_16, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_17, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_18, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_19, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_20, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_21, instance) );
- test->add( BOOST_CLASS_TEST_CASE( & test_unbounded_twolock_pool::test_case_22, instance) );
+ test->add( BOOST_TEST_CASE( & test_case_1) );
+ test->add( BOOST_TEST_CASE( & test_case_2) );
+ test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
+ test->add( BOOST_TEST_CASE( & test_case_5) );
+ test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
+ test->add( BOOST_TEST_CASE( & test_case_8) );
+ test->add( BOOST_TEST_CASE( & test_case_9) );
+ test->add( BOOST_TEST_CASE( & test_case_10) );
+ test->add( BOOST_TEST_CASE( & test_case_11) );
+ test->add( BOOST_TEST_CASE( & test_case_12) );
+ test->add( BOOST_TEST_CASE( & test_case_13) );
+ test->add( BOOST_TEST_CASE( & test_case_14) );
+ test->add( BOOST_TEST_CASE( & test_case_15) );
+ test->add( BOOST_TEST_CASE( & test_case_16) );
+ test->add( BOOST_TEST_CASE( & test_case_17) );
+ test->add( BOOST_TEST_CASE( & test_case_18) );
+ test->add( BOOST_TEST_CASE( & test_case_19) );
+ test->add( BOOST_TEST_CASE( & test_case_20) );
+ test->add( BOOST_TEST_CASE( & test_case_21) );
+ test->add( BOOST_TEST_CASE( & test_case_22) );
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