|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56774 - in sandbox/async: boost boost/tp boost/tp/detail libs/tp libs/tp/build libs/tp/doc libs/tp/doc/html libs/tp/doc/html/boost_threadpool libs/tp/examples libs/tp/src libs/tp/test
From: vicente.botet_at_[hidden]
Date: 2009-10-13 03:35:37
Author: viboes
Date: 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
New Revision: 56774
URL: http://svn.boost.org/trac/boost/changeset/56774
Log:
TBoost.Async:
* Added ThreadPool library
Added:
sandbox/async/boost/tp/
sandbox/async/boost/tp.hpp (contents, props changed)
sandbox/async/boost/tp/bounded_channel.hpp (contents, props changed)
sandbox/async/boost/tp/default_pool.hpp (contents, props changed)
sandbox/async/boost/tp/detail/
sandbox/async/boost/tp/detail/bind_processor.hpp (contents, props changed)
sandbox/async/boost/tp/detail/bind_processor_aix.hpp (contents, props changed)
sandbox/async/boost/tp/detail/bind_processor_hpux.hpp (contents, props changed)
sandbox/async/boost/tp/detail/bind_processor_irix.hpp (contents, props changed)
sandbox/async/boost/tp/detail/bind_processor_linux.hpp (contents, props changed)
sandbox/async/boost/tp/detail/bind_processor_solaris.hpp (contents, props changed)
sandbox/async/boost/tp/detail/bind_processor_windows.hpp (contents, props changed)
sandbox/async/boost/tp/detail/callable.hpp (contents, props changed)
sandbox/async/boost/tp/detail/guard.hpp (contents, props changed)
sandbox/async/boost/tp/detail/info.hpp (contents, props changed)
sandbox/async/boost/tp/detail/interrupter.hpp (contents, props changed)
sandbox/async/boost/tp/detail/worker.hpp (contents, props changed)
sandbox/async/boost/tp/detail/wsq.hpp (contents, props changed)
sandbox/async/boost/tp/exceptions.hpp (contents, props changed)
sandbox/async/boost/tp/fifo.hpp (contents, props changed)
sandbox/async/boost/tp/info.hpp (contents, props changed)
sandbox/async/boost/tp/lifo.hpp (contents, props changed)
sandbox/async/boost/tp/pool.hpp (contents, props changed)
sandbox/async/boost/tp/poolsize.hpp (contents, props changed)
sandbox/async/boost/tp/priority.hpp (contents, props changed)
sandbox/async/boost/tp/scanns.hpp (contents, props changed)
sandbox/async/boost/tp/smart.hpp (contents, props changed)
sandbox/async/boost/tp/task.hpp (contents, props changed)
sandbox/async/boost/tp/unbounded_channel.hpp (contents, props changed)
sandbox/async/boost/tp/watermark.hpp (contents, props changed)
sandbox/async/libs/tp/
sandbox/async/libs/tp/build/
sandbox/async/libs/tp/build/Jamfile.v2 (contents, props changed)
sandbox/async/libs/tp/doc/
sandbox/async/libs/tp/doc/Jamfile.v2 (contents, props changed)
sandbox/async/libs/tp/doc/acknowledgement.qbk (contents, props changed)
sandbox/async/libs/tp/doc/channel.qbk (contents, props changed)
sandbox/async/libs/tp/doc/exceptions_ref.qbk (contents, props changed)
sandbox/async/libs/tp/doc/forkjoin.qbk (contents, props changed)
sandbox/async/libs/tp/doc/html/
sandbox/async/libs/tp/doc/html/boost_threadpool/
sandbox/async/libs/tp/doc/html/boost_threadpool/acknowledgement.html (contents, props changed)
sandbox/async/libs/tp/doc/html/boost_threadpool/channel.html (contents, props changed)
sandbox/async/libs/tp/doc/html/boost_threadpool/forkjoin.html (contents, props changed)
sandbox/async/libs/tp/doc/html/boost_threadpool/pool.html (contents, props changed)
sandbox/async/libs/tp/doc/html/boost_threadpool/reference.html (contents, props changed)
sandbox/async/libs/tp/doc/html/boost_threadpool/scheduling.html (contents, props changed)
sandbox/async/libs/tp/doc/html/boost_threadpool/task.html (contents, props changed)
sandbox/async/libs/tp/doc/html/boost_threadpool/this_task.html (contents, props changed)
sandbox/async/libs/tp/doc/html/index.html (contents, props changed)
sandbox/async/libs/tp/doc/introduction.qbk (contents, props changed)
sandbox/async/libs/tp/doc/meta_ref.qbk (contents, props changed)
sandbox/async/libs/tp/doc/pool.qbk (contents, props changed)
sandbox/async/libs/tp/doc/pool_ref.qbk (contents, props changed)
sandbox/async/libs/tp/doc/poolsize_ref.qbk (contents, props changed)
sandbox/async/libs/tp/doc/reference.qbk (contents, props changed)
sandbox/async/libs/tp/doc/scanns_ref.qbk (contents, props changed)
sandbox/async/libs/tp/doc/scheduling.qbk (contents, props changed)
sandbox/async/libs/tp/doc/stacksize_ref.qbk (contents, props changed)
sandbox/async/libs/tp/doc/task.qbk (contents, props changed)
sandbox/async/libs/tp/doc/task_ref.qbk (contents, props changed)
sandbox/async/libs/tp/doc/this_task.qbk (contents, props changed)
sandbox/async/libs/tp/doc/this_task_ref.qbk (contents, props changed)
sandbox/async/libs/tp/doc/threadpool.qbk (contents, props changed)
sandbox/async/libs/tp/doc/threadpool.xml (contents, props changed)
sandbox/async/libs/tp/doc/watermark_ref.qbk (contents, props changed)
sandbox/async/libs/tp/examples/
sandbox/async/libs/tp/examples/Jamfile.v2 (contents, props changed)
sandbox/async/libs/tp/examples/fork_join.cpp (contents, props changed)
sandbox/async/libs/tp/examples/interrupt.cpp (contents, props changed)
sandbox/async/libs/tp/examples/parallel_sort.cpp (contents, props changed)
sandbox/async/libs/tp/examples/pending.cpp (contents, props changed)
sandbox/async/libs/tp/examples/priority.cpp (contents, props changed)
sandbox/async/libs/tp/examples/reschedule_until.cpp (contents, props changed)
sandbox/async/libs/tp/examples/shutdonw_now.cpp (contents, props changed)
sandbox/async/libs/tp/examples/smart.cpp (contents, props changed)
sandbox/async/libs/tp/examples/spread_over_hardware.cpp (contents, props changed)
sandbox/async/libs/tp/examples/submit.cpp (contents, props changed)
sandbox/async/libs/tp/src/
sandbox/async/libs/tp/src/callable.cpp (contents, props changed)
sandbox/async/libs/tp/src/default_pool.cpp (contents, props changed)
sandbox/async/libs/tp/src/guard.cpp (contents, props changed)
sandbox/async/libs/tp/src/interrupter.cpp (contents, props changed)
sandbox/async/libs/tp/src/poolsize.cpp (contents, props changed)
sandbox/async/libs/tp/src/scanns.cpp (contents, props changed)
sandbox/async/libs/tp/src/watermark.cpp (contents, props changed)
sandbox/async/libs/tp/src/worker.cpp (contents, props changed)
sandbox/async/libs/tp/test/
sandbox/async/libs/tp/test/Jamfile.v2 (contents, props changed)
sandbox/async/libs/tp/test/test_bounded_queue_fifo.cpp (contents, props changed)
sandbox/async/libs/tp/test/test_bounded_queue_lifo.cpp (contents, props changed)
sandbox/async/libs/tp/test/test_bounded_queue_priority.cpp (contents, props changed)
sandbox/async/libs/tp/test/test_bounded_queue_smart.cpp (contents, props changed)
sandbox/async/libs/tp/test/test_functions.hpp (contents, props changed)
sandbox/async/libs/tp/test/test_unbounded_queue_fifo.cpp (contents, props changed)
sandbox/async/libs/tp/test/test_unbounded_queue_lifo.cpp (contents, props changed)
sandbox/async/libs/tp/test/test_unbounded_queue_priority.cpp (contents, props changed)
sandbox/async/libs/tp/test/test_unbounded_queue_smart.cpp (contents, props changed)
Added: sandbox/async/boost/tp.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,23 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_H
+#define BOOST_TP_H
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/fifo.hpp>
+#include <boost/tp/info.hpp>
+#include <boost/tp/lifo.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/priority.hpp>
+#include <boost/tp/scanns.hpp>
+#include <boost/tp/smart.hpp>
+#include <boost/tp/task.hpp>
+#include <boost/tp/unbounded_channel.hpp>
+#include <boost/tp/watermark.hpp>
+
+#endif // BOOST_TP_H
+
Added: sandbox/async/boost/tp/bounded_channel.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/bounded_channel.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,409 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_BOUNDED_CHANNEL_H
+#define BOOST_TP_BOUNDED_CHANNEL_H
+
+#include <cstddef>
+#include <vector>
+
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/function.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <boost/tp/detail/callable.hpp>
+#include <boost/tp/detail/interrupter.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/watermark.hpp>
+
+namespace boost { namespace tp
+{
+template< typename SchedulingPolicy >
+class bounded_channel
+{
+private:
+ typedef SchedulingPolicy scheduling_policy;
+ typedef typename scheduling_policy::template impl<
+ detail::callable
+ > queue;
+
+public:
+ typedef typename queue::item item;
+ typedef scheduling_policy scheduler_type;
+
+private:
+ enum channel_state
+ {
+ channel_active,
+ channel_deactive,
+ channel_deactive_now
+ };
+
+ channel_state state_;
+ queue queue_;
+ shared_mutex mtx_;
+ condition not_empty_cond_;
+ condition not_full_cond_;
+ std::size_t hwm_;
+ std::size_t lwm_;
+
+ bool active_() const
+ { return state_ == channel_active; }
+
+ bool deactive_() const
+ { return state_ == channel_deactive; }
+
+ bool deactive_now_() const
+ { return state_ == channel_deactive_now; }
+
+ void activate_()
+ { state_ = channel_active; }
+
+ void clear_()
+ {
+ BOOST_ASSERT( ! active_() );
+ queue_.clear();
+ BOOST_ASSERT( empty_() );
+ }
+
+ void deactivate_()
+ {
+ if ( active_() )
+ {
+ state_ = channel_deactive;
+ not_empty_cond_.notify_all();
+ }
+
+ BOOST_ASSERT( deactive_() );
+ }
+
+ void deactivate_now_()
+ {
+ if ( active_() )
+ {
+ state_ = channel_deactive_now;
+ not_empty_cond_.notify_all();
+ }
+
+ BOOST_ASSERT( deactive_now_() );
+ }
+
+ const std::vector< detail::callable > drain_()
+ {
+ BOOST_ASSERT( deactive_now_() );
+ std::vector< detail::callable > unprocessed;
+ unprocessed.reserve( queue_.size() );
+ BOOST_FOREACH( item itm, queue_)
+ { unprocessed.push_back( itm.ca() ); }
+ clear_();
+ BOOST_ASSERT( empty_() );
+ return unprocessed;
+ }
+
+ bool empty_() const
+ { return queue_.empty(); }
+
+ bool full_() const
+ { return size_() >= hwm_; }
+
+ std::size_t size_() const
+ { return queue_.size(); }
+
+ void upper_bound_( std::size_t hwm)
+ {
+ if ( lwm_ > hwm )
+ throw invalid_watermark("low watermark must be less than or equal to high watermark");
+ std::size_t tmp( hwm_);
+ hwm_ = hwm;
+ if ( hwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ void lower_bound_( std::size_t lwm)
+ {
+ if ( lwm > hwm_ )
+ throw invalid_watermark("low watermark must be less than or equal to high watermark");
+ std::size_t tmp( lwm_);
+ lwm_ = lwm;
+ if ( lwm_ > tmp) not_full_cond_.notify_one();
+ }
+
+ void put_(
+ item const& itm,
+ unique_lock< shared_mutex > & lk)
+ {
+ not_full_cond_.wait(
+ lk,
+ bind(
+ & bounded_channel::producers_activate_,
+ this) );
+ if ( ! active_() )
+ throw task_rejected("channel is not active");
+ queue_.push( itm);
+ not_empty_cond_.notify_one();
+ }
+
+ template< typename Duration >
+ void put_(
+ item const& itm,
+ Duration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( ! not_full_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & bounded_channel::producers_activate_,
+ this) ) )
+ throw task_rejected("timed out");
+ if ( ! active_() )
+ throw task_rejected("channel is not active");
+ queue_.push( itm);
+ not_empty_cond_.notify_one();
+ }
+
+ bool take_(
+ detail::callable & ca,
+ detail::interrupter & intr,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( deactive_now_() || ( deactive_() && empty_() ) )
+ return false;
+ try
+ {
+ not_empty_cond_.wait(
+ lk,
+ bind(
+ & bounded_channel::consumers_activate_,
+ this) );
+ }
+ catch ( thread_interrupted const& e)
+ { return false; }
+ if ( deactive_now_() || ( deactive_() && empty_() ) )
+ return false;
+ item itm( queue_.pop() );
+ ca = itm.ca();
+ intr = itm.intr();
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // for submiting an action object
+ not_full_cond_.notify_all();
+ }
+ return ! ca.empty();
+ }
+
+ template< typename Duration >
+ bool take_(
+ detail::callable & ca,
+ detail::interrupter & intr,
+ Duration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( deactive_now_() || ( deactive_() && empty_() ) )
+ return false;
+ try
+ {
+ if ( ! not_empty_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & bounded_channel::consumers_activate_,
+ this) ) )
+ return false;
+ }
+ catch ( thread_interrupted const& e)
+ { return false; }
+ if ( deactive_now_() || ( deactive_() && empty_() ) )
+ return false;
+ item itm( queue_.pop() );
+ ca = itm.ca();
+ intr = itm.intr();
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // for submiting an action object
+ not_full_cond_.notify_all();
+ }
+ return ! ca.empty();
+ }
+
+ bool try_take_(
+ detail::callable & ca,
+ detail::interrupter & intr)
+ {
+ if ( deactive_now_() || empty_() )
+ return false;
+ item itm( queue_.pop() );
+ ca = itm.ca();
+ intr = itm.intr();
+ if ( size_() <= lwm_)
+ {
+ if ( lwm_ == hwm_)
+ not_full_cond_.notify_one();
+ else
+ // more than one producer could be waiting
+ // for submiting an action object
+ not_full_cond_.notify_all();
+ }
+ return ! ca.empty();
+ }
+
+ bool producers_activate_() const
+ { return ! active_() || ! full_(); }
+
+ bool consumers_activate_() const
+ { return ! active_() || ! empty_(); }
+
+public:
+ bounded_channel(
+ high_watermark const& hwm,
+ low_watermark const& lwm)
+ :
+ state_( channel_active),
+ queue_(),
+ mtx_(),
+ not_empty_cond_(),
+ not_full_cond_(),
+ hwm_( hwm),
+ lwm_( lwm)
+ {
+ if ( lwm_ > hwm_ )
+ throw invalid_watermark("low watermark must be less than or equal to high watermark");
+ }
+
+ bool active()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return active_();
+ }
+
+ void activate()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ activate_();
+ }
+
+ void clear()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ clear_();
+ }
+
+ bool deactive()
+ { return ! active(); }
+
+ void deactivate()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ deactivate_();
+ }
+
+ void deactivate_now()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ deactivate_now_();
+ }
+
+ const std::vector< detail::callable > drain()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return drain_();
+ }
+
+ bool empty()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return empty_();
+ }
+
+ bool full()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return full_();
+ }
+
+ std::size_t upper_bound()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return hwm_;
+ }
+
+ void upper_bound( std::size_t hwm)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ upper_bound_( hwm);
+ }
+
+ std::size_t lower_bound()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return lwm_;
+ }
+
+ void lower_bound( std::size_t lwm)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ lower_bound_( lwm);
+ }
+
+ std::size_t size()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return size_();
+ }
+
+ void put( item const& itm)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( itm, lk);
+ }
+
+ template< typename Duration >
+ void put(
+ item const& itm,
+ Duration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( itm, rel_time, lk);
+ }
+
+ bool take(
+ detail::callable & ca,
+ detail::interrupter & intr)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, intr, lk);
+ }
+
+ template< typename Duration >
+ bool take(
+ detail::callable & ca,
+ detail::interrupter & intr,
+ Duration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, intr, rel_time, lk);
+ }
+
+ bool try_take(
+ detail::callable & ca,
+ detail::interrupter & intr)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return try_take_( ca, intr);
+ }
+};
+} }
+
+#endif // BOOST_TP_BOUNDED_CHANNEL_H
Added: sandbox/async/boost/tp/default_pool.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/default_pool.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,27 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DEFAULT_POOL_H
+#define BOOST_TP_DEFAULT_POOL_H
+
+#include <boost/tp/fifo.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/unbounded_channel.hpp>
+
+namespace boost { namespace tp
+{
+typedef pool< unbounded_channel< fifo > > default_pool;
+
+namespace detail
+{
+struct static_pool
+{ static default_pool instance; };
+}
+
+inline
+default_pool & get_default_pool()
+{ return detail::static_pool::instance; }
+} }
+
+#endif // BOOST_TP_DEFAULT_POOL_H
Added: sandbox/async/boost/tp/detail/bind_processor.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/bind_processor.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,30 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_THREAD_BIND_PROCESSOR_H
+#define BOOST_THREAD_BIND_PROCESSOR_H
+
+#include <boost/config.hpp>
+
+#define BOOST_THREAD_BIND_PROCESSOR_AFFINITY 1
+
+#if defined(linux) || defined(__linux) || defined(__linux__)
+#include <boost/tp/detail/bind_processor_linux.hpp>
+// #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+// #include <boost/tp/detail/bind_processor_bsd.hpp>
+#elif defined(sun) || defined(__sun)
+#include <boost/tp/detail/bind_processor_solaris.hpp>
+#elif defined(__sgi)
+#include <boost/tp/detail/bind_processor_irix.hpp>
+#elif defined(__IBMCPP__) || defined(_AIX)
+#include <boost/tp/detail/bind_processor_aix.hpp>
+#elif defined(__hpux)
+#include <boost/tp/detail/bind_processor_hpux.hpp>
+#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+#include <boost/tp/detail/bind_processor_windows.hpp>
+#else
+#undef BOOST_THREAD_BIND_PROCESSOR_AFFINITY
+#endif
+
+#endif // BOOST_THREAD_BIND_PROCESSOR_H
Added: sandbox/async/boost/tp/detail/bind_processor_aix.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/bind_processor_aix.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,45 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_BIND_PROCESSOR_AIX_H
+#define BOOST_TP_DETAIL_BIND_PROCESSOR_AIX_H
+
+extern "C"
+{
+#include <sys/processor.h>
+#include <sys/thread.h>
+}
+
+#include <boost/assert.hpp>
+#include <boost/thread.hpp>
+#include <boost/system/system_error.hpp>
+
+namespace boost { namespace this_thread
+{
+ inline
+ void bind_to_processor( unsigned int n)
+ {
+ BOOST_ASSERT( n >= 0);
+ BOOST_ASSERT( n < boost::thread::hardware_concurrency() );
+
+ if ( ::bindprocessor( BINDTHREAD, ::thread_self(), static_cast< cpu_t >( n) ) == -1)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno,
+ boost::system::system_category) );
+ }
+
+
+ inline
+ void bind_to_any_processor()
+ {
+ if ( ::bindprocessor( BINDTHREAD, ::thread_self(), PROCESSOR_CLASS_ANY) == -1)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno,
+ boost::system::system_category) );
+ }
+}}
+
+#endif // BOOST_TP_DETAIL_BIND_PROCESSOR_AIX_H
Added: sandbox/async/boost/tp/detail/bind_processor_hpux.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/bind_processor_hpux.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,57 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_BIND_PROCESSOR_HPUX_H
+#define BOOST_TP_DETAIL_BIND_PROCESSOR_HPUX_H
+
+extern "C"
+{
+#include <sys/pthread.h>
+}
+
+#include <boost/assert.hpp>
+#include <boost/thread.hpp>
+#include <boost/system/system_error.hpp>
+
+namespace boost { namespace this_thread
+{
+ inline
+ void bind_to_processor( unsigned int n)
+ {
+ BOOST_ASSERT( n >= 0);
+ BOOST_ASSERT( n < boost::thread::hardware_concurrency() );
+
+ ::pthread_spu_t spu;
+ int errno_(
+ ::pthread_processor_bind_np(
+ PTHREAD_BIND_FORCED_NP,
+ & spu,
+ static_cast< pthread_spu_t >( n),
+ PTHREAD_SELFTID_NP) );
+ if ( errno_ != 0)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno_,
+ boost::system::system_category) );
+ }
+
+ inline
+ void bind_to_any_processor()
+ {
+ ::pthread_spu_t spu;
+ int errno_(
+ ::pthread_processor_bind_np(
+ PTHREAD_BIND_FORCED_NP,
+ & spu,
+ PTHREAD_SPUFLOAT_NP,
+ PTHREAD_SELFTID_NP) );
+ if ( errno_ != 0)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno_,
+ boost::system::system_category) );
+ }
+}}
+
+#endif // BOOST_TP_DETAIL_BIND_PROCESSOR_HPUX_H
Added: sandbox/async/boost/tp/detail/bind_processor_irix.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/bind_processor_irix.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,36 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_BIND_PROCESSOR_IRIX_H
+#define BOOST_TP_DETAIL_BIND_PROCESSOR_IRIX_H
+
+extern "C"
+{
+#include <pthread.h>
+}
+
+#include <boost/assert.hpp>
+#include <boost/thread.hpp>
+#include <boost/system/system_error.hpp>
+
+namespace boost { namespace this_thread
+{
+ inline
+ void bind_to_processor( unsigned int n)
+ {
+ BOOST_ASSERT( n >= 0);
+ BOOST_ASSERT( n < boost::thread::hardware_concurrency() );
+
+ int errno_( ::pthread_setrunon_np( n) );
+ if ( errno_ != 0)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno_,
+ boost::system::system_category) );
+ }
+
+ // bind_to_any_processor() can not be supported
+}}
+
+#endif // BOOST_TP_DETAIL_BIND_PROCESSOR_IRIX_H
Added: sandbox/async/boost/tp/detail/bind_processor_linux.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/bind_processor_linux.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,58 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_BIND_PRCESSOR_LINUX_H
+#define BOOST_TP_DETAIL_BIND_PRCESSOR_LINUX_H
+
+extern "C"
+{
+#include <pthread.h>
+#include <sched.h>
+}
+
+#include <boost/assert.hpp>
+#include <boost/thread.hpp>
+#include <boost/system/system_error.hpp>
+
+namespace boost { namespace this_thread
+{
+ inline
+ void bind_to_processor( unsigned int n)
+ {
+ BOOST_ASSERT( n >= 0);
+ BOOST_ASSERT( n < CPU_SETSIZE);
+ BOOST_ASSERT( n < boost::thread::hardware_concurrency() );
+
+ cpu_set_t cpuset;
+ CPU_ZERO( & cpuset);
+ CPU_SET( n, & cpuset);
+
+ int errno_( ::pthread_setaffinity_np( ::pthread_self(), sizeof( cpuset), & cpuset) );
+ if ( errno_ != 0)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno_,
+ boost::system::system_category) );
+ }
+
+ inline
+ void bind_to_any_processor()
+ {
+ cpu_set_t cpuset;
+ CPU_ZERO( & cpuset);
+
+ unsigned int max( boost::thread::hardware_concurrency() );
+ for ( unsigned int i( 0); i < max; ++i)
+ CPU_SET( i, & cpuset);
+
+ int errno_( ::pthread_setaffinity_np( ::pthread_self(), sizeof( cpuset), & cpuset) );
+ if ( errno_ != 0)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno_,
+ boost::system::system_category) );
+ }
+}}
+
+#endif // BOOST_TP_DETAIL_BIND_PRCESSOR_LINUX_H
Added: sandbox/async/boost/tp/detail/bind_processor_solaris.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/bind_processor_solaris.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,45 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_BIND_PROCESSOR_SOLARIS_H
+#define BOOST_TP_DETAIL_BIND_PROCESSOR_SOLARIS_H
+
+extern "C"
+{
+#include <sys/types.h>
+#include <sys/processor.h>
+#include <sys/procset.h>
+}
+
+#include <boost/assert.hpp>
+#include <boost/thread.hpp>
+#include <boost/system/system_error.hpp>
+
+namespace boost { namespace this_thread
+{
+ inline
+ void bind_to_processor( unsigned int n)
+ {
+ BOOST_ASSERT( n >= 0);
+ BOOST_ASSERT( n < boost::thread::hardware_concurrency() );
+
+ if ( ::processor_bind( P_LWPID, P_MYID, static_cast< processorid_t >( n), 0) == -1)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno,
+ boost::system::system_category) );
+ }
+
+ inline
+ void bind_to_any_processor()
+ {
+ if ( ::processor_bind( P_LWPID, P_MYID, PBIND_NONE, 0) == -1)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ errno,
+ boost::system::system_category) );
+ }
+}}
+
+#endif // BOOST_TP_DETAIL_BIND_PROCESSOR_SOLARIS_H
Added: sandbox/async/boost/tp/detail/bind_processor_windows.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/bind_processor_windows.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,47 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_BIND_PROCESSOR_WINDOWS_H
+#define BOOST_TP_DETAIL_BIND_PROCESSOR_WINDOWS_H
+
+extern "C"
+{
+#include <windows.h>
+}
+
+#include <boost/assert.hpp>
+#include <boost/thread.hpp>
+#include <boost/system/system_error.hpp>
+
+namespace boost { namespace this_thread
+{
+ inline
+ void bind_to_processor( unsigned int n)
+ {
+ BOOST_ASSERT( n >= 0);
+ BOOST_ASSERT( n < boost::thread::hardware_concurrency() );
+
+ if ( ::SetThreadAffinityMask( ::GetCurrentThread(), ( DWORD_PTR)1 << n) == 0)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ ::GetLastError(),
+ boost::system::system_category) );
+ }
+
+ inline
+ void bind_to_any_processor()
+ {
+ DWORD_PTR ptr( 1);
+ for ( unsigned int i( 0); i < boost::thread::hardware_concurrency(); ++i)
+ ptr = ptr << i;
+
+ if ( ::SetThreadAffinityMask( ::GetCurrentThread(), ptr) == 0)
+ throw boost::system::system_error(
+ boost::system::error_code(
+ ::GetLastError(),
+ boost::system::system_category) );
+ }
+}}
+
+#endif // BOOST_TP_DETAIL_BIND_PROCESSOR_WINDOWS_H
Added: sandbox/async/boost/tp/detail/callable.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/callable.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,57 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_CALLABLE_H
+#define BOOST_TP_DETAIL_CALLABLE_H
+
+#include <boost/future.hpp>
+
+#include <boost/thread/detail/move.hpp>
+
+namespace boost { namespace tp {
+namespace detail
+{
+class callable
+{
+private:
+ struct impl
+ {
+ virtual ~impl() {}
+ virtual void run() = 0;
+ };
+
+ template< typename T >
+ struct impl_wrapper
+ : public impl
+ {
+ packaged_task< T > tsk;
+
+ impl_wrapper( boost::detail::thread_move_t< packaged_task< T > > const& t)
+ : tsk( t)
+ {}
+
+ void run()
+ { tsk(); }
+ };
+
+ boost::shared_ptr< impl > impl_;
+
+public:
+ callable();
+
+ template< typename T >
+ callable( boost::detail::thread_move_t< packaged_task< T > > const& t)
+ : impl_( new impl_wrapper< T >( t) )
+ {}
+
+ void operator()();
+
+ bool empty() const;
+
+ void clear();
+};
+} } }
+
+#endif // BOOST_TP_DETAIL_CALLABLE_H
+
Added: sandbox/async/boost/tp/detail/guard.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/guard.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,29 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_GUARD_H
+#define BOOST_TP_DETAIL_GUARD_H
+
+#include <boost/assert.hpp>
+#include <boost/interprocess/detail/atomic.hpp>
+#include <boost/utility.hpp>
+
+namespace boost { namespace tp {
+namespace detail
+{
+class guard
+: private noncopyable
+{
+private:
+ volatile uint32_t & active_worker_;
+
+public:
+ guard( volatile uint32_t & active_worker);
+
+ ~guard();
+};
+} } }
+
+#endif // BOOST_TP_DETAIL_GUARD_H
+
Added: sandbox/async/boost/tp/detail/info.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/info.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,19 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_INFO_H
+#define BOOST_TP_DETAIL_INFO_H
+
+namespace boost { namespace tp {
+namespace detail
+{
+struct has_priority
+{};
+
+struct has_no_priority
+{};
+} } }
+
+#endif // BOOST_TP_DETAIL_INFO_H
+
Added: sandbox/async/boost/tp/detail/interrupter.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/interrupter.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,81 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_INTERRUPTER_H
+#define BOOST_TP_DETAIL_INTERRUPTER_H
+
+#include <boost/shared_ptr.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread_time.hpp>
+#include <boost/utility.hpp>
+
+namespace boost { namespace tp {
+namespace detail
+{
+class interrupter
+{
+private:
+ class impl
+ : private noncopyable
+ {
+ private:
+ bool interruption_requested_;
+ condition_variable cond_;
+ mutex mtx_;
+ shared_ptr< thread > thrd_;
+
+ void interrupt_();
+
+ public:
+ impl();
+
+ void set( shared_ptr< thread > const& thrd);
+
+ void reset();
+
+ void interrupt();
+
+ void interrupt_and_wait();
+
+ void interrupt_and_wait( system_time const& abs_time);
+
+ template< typename DurationType >
+ void interrupt_and_wait( DurationType const& rel_time)
+ {
+ unique_lock< mutex > lk( mtx_);
+ interrupt_();
+ cond_.timed_wait( lk, rel_time);
+ }
+
+ bool interruption_requested();
+ };
+
+ shared_ptr< impl > impl_;
+
+public:
+ interrupter();
+
+ void set( shared_ptr< thread > const& thrd);
+
+ void reset();
+
+ void interrupt();
+
+ void interrupt_and_wait();
+
+ void interrupt_and_wait( system_time const& abs_time);
+
+ template< typename DurationType >
+ void interrupt_and_wait( DurationType const& rel_time)
+ { impl_->interrupt_and_wait( rel_time); }
+
+ bool interruption_requested();
+};
+}
+} }
+
+#endif // BOOST_TP_DETAIL_INTERRUPTER_H
Added: sandbox/async/boost/tp/detail/worker.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/worker.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,156 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_WORKER_H
+#define BOOST_TP_DETAIL_WORKER_H
+
+#include <cstddef>
+#include <utility>
+
+#include <boost/assert.hpp>
+#include <boost/function.hpp>
+#include <boost/interprocess/sync/interprocess_semaphore.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/thread.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/detail/callable.hpp>
+#include <boost/tp/detail/interrupter.hpp>
+#include <boost/tp/detail/wsq.hpp>
+
+namespace boost {
+namespace tp {
+namespace detail
+{
+class worker
+{
+private:
+ static thread_specific_ptr< worker > tss_;
+
+ class impl : private noncopyable
+ {
+ private:
+ typedef std::pair< callable, interrupter > item;
+ shared_ptr< thread > thrd_;
+ wsq< item > wsq_;
+ interprocess::interprocess_semaphore shtdwn_sem_;
+ interprocess::interprocess_semaphore shtdwn_now_sem_;
+ bool shtdwn_;
+ std::size_t scns_;
+
+ public:
+ impl( function< void() > const&);
+
+ virtual ~impl() {}
+
+ const shared_ptr< thread > thrd() const;
+
+ const thread::id get_id() const;
+
+ void join() const;
+
+ void interrupt() const;
+
+ void put( callable const&, interrupter const&);
+
+ bool try_take( callable &, interrupter &);
+
+ bool try_steal( callable &, interrupter &);
+
+ bool empty();
+
+ void signal_shutdown();
+
+ void signal_shutdown_now();
+
+ bool shutdown();
+
+ bool shutdown_now();
+
+ std::size_t scanns() const;
+
+ void increment_scanns();
+
+ void reset_scanns();
+
+ virtual void reschedule_until( function< bool() > const&) = 0;
+ };
+
+ template< typename Pool >
+ class impl_pool : public impl
+ {
+ private:
+ Pool & p_;
+
+ public:
+ impl_pool( Pool & p, function< void() > const& fn)
+ : impl( fn), p_( p)
+ {}
+
+ void reschedule_until( function< bool() > const& pred)
+ { p_.reschedule_until( pred); }
+
+ Pool & get_pool() const
+ { return p_; }
+ };
+
+ shared_ptr< impl > impl_;
+
+public:
+ template< typename Pool >
+ worker(
+ Pool & pool,
+ function< void() > const& fn)
+ : impl_( new impl_pool< Pool >( pool, fn) )
+ {}
+
+ const shared_ptr< thread > thrd() const;
+
+ const thread::id get_id() const;
+
+ void join() const;
+
+ void interrupt() const;
+
+ void put( callable const&, interrupter const&);
+
+ bool try_take( callable &, interrupter &);
+
+ bool try_steal( callable &, interrupter &);
+
+ bool empty() const;
+
+ void signal_shutdown();
+
+ void signal_shutdown_now();
+
+ bool shutdown();
+
+ bool shutdown_now();
+
+ std::size_t scanns() const;
+
+ void increment_scanns();
+
+ void reset_scanns();
+
+ void reschedule_until( function< bool() > const&);
+
+ template< typename Pool >
+ Pool & get_thread_pool() const
+ {
+ impl_pool< Pool > * p( dynamic_cast< impl_pool< Pool > * >( impl_.get() ) );
+ BOOST_ASSERT( p);
+ return p->get_pool();
+ }
+
+ static worker * tss_get();
+
+ static void tss_reset( worker * w);
+};
+
+} } }
+
+#endif // BOOST_TP_DETAIL_WORKER_H
+
Added: sandbox/async/boost/tp/detail/wsq.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/detail/wsq.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,170 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_DETAIL_WSQ_H
+#define BOOST_TP_DETAIL_WSQ_H
+
+#include <utility>
+
+#include <boost/assert.hpp>
+#include <boost/interprocess/detail/atomic.hpp>
+#include <boost/foreach.hpp>
+#include <boost/function.hpp>
+#include <boost/shared_array.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/detail/interrupter.hpp>
+
+namespace boost { namespace tp {
+namespace detail
+{
+template< typename T >
+class wsq
+: private noncopyable
+{
+private:
+ class impl
+ {
+ private:
+ const int initial_size_;
+ shared_array< T > array_;
+ int capacity_;
+ int mask_;
+ volatile uint32_t head_idx_;
+ volatile uint32_t tail_idx_;
+ recursive_mutex mtx_;
+
+ public:
+ impl()
+ :
+ initial_size_( 32),
+ array_( new T[ initial_size_]),
+ capacity_( initial_size_),
+ mask_( initial_size_ - 1),
+ head_idx_( 0),
+ tail_idx_( 0),
+ mtx_()
+ {}
+
+ bool empty() const
+ { return head_idx_ >= tail_idx_; }
+
+ std::size_t size() const
+ { return tail_idx_ - head_idx_; }
+
+ void put( T const& t)
+ {
+ uint32_t tail( tail_idx_);
+ if ( tail <= head_idx_ + mask_)
+ {
+ array_[tail & mask_] = t;
+ tail_idx_ = tail + 1;
+ }
+ else
+ {
+ unique_lock< recursive_mutex > lk( mtx_);
+ uint32_t head( head_idx_);
+ int count( size() );
+
+ if ( count >= mask_)
+ {
+ capacity_ <<= 1;
+ shared_array< T > array( new T[capacity_]);
+ for ( int i( 0); i != count; ++i)
+ array[i] = array_[(i + head) & mask_];
+ array_.swap( array);
+ head_idx_ = 0;
+ tail_idx_ = tail = count;
+ mask_ = (mask_ << 1) | 1;
+ }
+ array_[tail & mask_] = t;
+ tail_idx_ = tail + 1;
+ }
+ }
+
+ bool try_take( T & t)
+ {
+ uint32_t tail( tail_idx_);
+ if ( tail == 0)
+ return false;
+ tail -= 1;
+ interprocess::detail::atomic_write32( & tail_idx_, tail);
+ if ( head_idx_ <= tail)
+ {
+ t = array_[tail & mask_];
+ return true;
+ }
+ else
+ {
+ unique_lock< recursive_mutex > lk( mtx_);
+ if ( head_idx_ <= tail)
+ {
+ t = array_[tail & mask_];
+ return true;
+ }
+ else
+ {
+ tail_idx_ = tail + 1;
+ return false;
+ }
+ }
+ }
+
+ bool try_steal( T & t)
+ {
+ recursive_mutex::scoped_try_lock lk( mtx_);
+ if ( lk.owns_lock() )
+ {
+ uint32_t head( head_idx_);
+ interprocess::detail::atomic_write32( & head_idx_, head + 1);
+ if ( head < tail_idx_)
+ {
+ t = array_[head & mask_];
+ return true;
+ }
+ else
+ {
+ head_idx_ = head;
+ return false;
+ }
+ }
+ return false;
+ }
+ };
+
+ shared_ptr< impl > impl_;
+
+public:
+ wsq()
+ : impl_( new impl() )
+ {}
+
+ bool empty() const
+ { return impl_->empty(); }
+
+ std::size_t size() const
+ { return impl_->size(); }
+
+ void put( T const& t)
+ { impl_->put( t); }
+
+ bool try_take( T & t)
+ { return impl_->try_take( t); }
+
+ bool try_steal( T & t)
+ { return impl_->try_steal( t); }
+
+ void swap( wsq & queue)
+ {
+ if ( this == & queue) return;
+ impl_.swap( queue.impl_);
+ }
+};
+} } }
+
+#endif // BOOST_TP_DETAIL_WSQ_H
+
Added: sandbox/async/boost/tp/exceptions.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/exceptions.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,59 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_EXCEPTIONS_H
+#define BOOST_TP_EXCEPTIONS_H
+
+#include <stdexcept>
+#include <string>
+
+namespace boost { namespace tp
+{
+class invalid_poolsize
+: public std::invalid_argument
+{
+public:
+ invalid_poolsize( std::string const& msg)
+ : std::invalid_argument( msg)
+ {}
+};
+
+class invalid_scanns
+: public std::invalid_argument
+{
+public:
+ invalid_scanns( std::string const& msg)
+ : std::invalid_argument( msg)
+ {}
+};
+
+class invalid_timeduration
+: public std::invalid_argument
+{
+public:
+ invalid_timeduration( std::string const& msg)
+ : std::invalid_argument( msg)
+ {}
+};
+
+class invalid_watermark
+: public std::invalid_argument
+{
+public:
+ invalid_watermark( std::string const& msg)
+ : std::invalid_argument( msg)
+ {}
+};
+
+class task_rejected
+: public std::runtime_error
+{
+public:
+ task_rejected( std::string const& msg)
+ : std::runtime_error( msg)
+ {}
+};
+} }
+
+#endif // BOOST_TP_EXCEPTIONS_H
Added: sandbox/async/boost/tp/fifo.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/fifo.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,92 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_FIFO_H
+#define BOOST_TP_FIFO_H
+
+#include <cstddef>
+#include <list>
+
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+
+#include <boost/tp/detail/info.hpp>
+#include <boost/tp/detail/interrupter.hpp>
+
+namespace boost { namespace tp
+{
+struct fifo
+{
+ typedef detail::has_no_priority priority_tag_type;
+
+ template< typename Callable >
+ class impl
+ {
+ private:
+ typedef Callable callable;
+
+ public:
+ class item
+ {
+ private:
+ callable ca_;
+ detail::interrupter intr_;
+
+ public:
+ item(
+ callable const& ca,
+ detail::interrupter const& intr)
+ : ca_( ca), intr_( intr)
+ { BOOST_ASSERT( ! ca_.empty() ); }
+
+ const callable ca() const
+ { return ca_; }
+
+ const detail::interrupter intr() const
+ { return intr_; }
+ };
+
+ typedef typename std::list< item >::iterator iterator;
+ typedef typename std::list< item >::const_iterator const_iterator;
+
+ private:
+ std::list< item > lst_;
+
+ public:
+ void push( item const& itm)
+ { lst_.push_back( itm); }
+
+ const item pop()
+ {
+ item itm( lst_.front() );
+ lst_.pop_front();
+ return itm;
+ }
+
+ std::size_t size() const
+ { return lst_.size(); }
+
+ bool empty() const
+ { return lst_.empty(); }
+
+ void clear()
+ { lst_.clear(); }
+
+ const iterator begin()
+ { return lst_.begin(); }
+
+ const const_iterator begin() const
+ { return lst_.begin(); }
+
+ const iterator end()
+ { return lst_.end(); }
+
+ const const_iterator end() const
+ { return lst_.end(); }
+ };
+};
+} }
+
+#endif // BOOST_TP_FIFO_H
Added: sandbox/async/boost/tp/info.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/info.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,34 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_INFO_H
+#define BOOST_TP_INFO_H
+
+#include <boost/mpl/bool.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/tp/detail/info.hpp>
+
+namespace boost { namespace tp
+{
+template< typename Pool >
+struct has_priority
+:
+public mpl::bool_<
+ is_same<
+ detail::has_priority,
+ typename Pool::scheduler_type::priority_tag_type
+ >::value
+>
+{};
+
+template< typename Pool >
+struct priority_type
+{
+ typedef typename Pool::scheduler_type::attribute_type type;
+};
+} }
+
+#endif // BOOST_TP_INFO_H
+
Added: sandbox/async/boost/tp/lifo.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/lifo.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,92 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_LIFO_H
+#define BOOST_TP_LIFO_H
+
+#include <cstddef>
+#include <list>
+
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+
+#include <boost/tp/detail/info.hpp>
+#include <boost/tp/detail/interrupter.hpp>
+
+namespace boost { namespace tp
+{
+struct lifo
+{
+ typedef detail::has_no_priority priority_tag_type;
+
+ template< typename Callable >
+ class impl
+ {
+ private:
+ typedef Callable callable;
+
+ public:
+ class item
+ {
+ private:
+ callable ca_;
+ detail::interrupter intr_;
+
+ public:
+ item(
+ callable const& ca,
+ detail::interrupter const& intr)
+ : ca_( ca), intr_( intr)
+ { BOOST_ASSERT( ! ca_.empty() ); }
+
+ const callable ca() const
+ { return ca_; }
+
+ const detail::interrupter intr() const
+ { return intr_; }
+ };
+
+ typedef typename std::list< item >::iterator iterator;
+ typedef typename std::list< item >::const_iterator const_iterator;
+
+ private:
+ std::list< item > lst_;
+
+ public:
+ void push( item const& itm)
+ { lst_.push_front( itm); }
+
+ const item pop()
+ {
+ item itm( lst_.front() );
+ lst_.pop_front();
+ return itm;
+ }
+
+ std::size_t size() const
+ { return lst_.size(); }
+
+ bool empty() const
+ { return lst_.empty(); }
+
+ void clear()
+ { lst_.clear(); }
+
+ const iterator begin()
+ { return lst_.begin(); }
+
+ const const_iterator begin() const
+ { return lst_.begin(); }
+
+ const iterator end()
+ { return lst_.end(); }
+
+ const const_iterator end() const
+ { return lst_.end(); }
+ };
+};
+} }
+
+#endif // BOOST_TP_LIFO_H
Added: sandbox/async/boost/tp/pool.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/pool.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,618 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_POOL_H
+#define BOOST_TP_POOL_H
+
+#include <cstddef>
+#include <list>
+#include <utility>
+#include <vector>
+
+#include <boost/future.hpp>
+
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/function.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/random_access_index.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/random.hpp>
+#include <boost/ref.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/thread.hpp>
+#include <boost/utility.hpp>
+#include <boost/utility/result_of.hpp>
+
+#include <boost/tp/detail/callable.hpp>
+#include <boost/tp/detail/guard.hpp>
+#include <boost/tp/detail/interrupter.hpp>
+#ifdef BOOST_BIND_WORKER_TO_PROCESSORS
+#include <boost/tp/detail/bind_processor.hpp>
+#endif
+#include <boost/tp/detail/worker.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/scanns.hpp>
+#include <boost/tp/task.hpp>
+#include <boost/tp/watermark.hpp>
+
+namespace boost {
+namespace this_task
+{
+template< typename Pred >
+void reschedule_until( Pred const& pred)
+{
+ tp::detail::worker * w( tp::detail::worker::tss_get() );
+ BOOST_ASSERT( w);
+ w->reschedule_until( pred);
+}
+
+template< typename Pool >
+Pool & get_thread_pool()
+{
+ tp::detail::worker * w( tp::detail::worker::tss_get() );
+ BOOST_ASSERT( w);
+ return w->get_thread_pool< Pool >();
+}
+
+inline
+bool is_worker()
+{ return tp::detail::worker::tss_get() != 0; }
+
+inline
+thread::id worker_id()
+{
+ tp::detail::worker * w( tp::detail::worker::tss_get() );
+ BOOST_ASSERT( w);
+ return w->get_id();
+}
+}
+
+namespace tp
+{
+template< typename Channel >
+class pool : private noncopyable
+{
+private:
+ template< typename Pred >
+ friend void this_task::reschedule_until( Pred const&);
+
+ template< typename Pool >
+ friend Pool & this_task::get_thread_pool();
+
+ friend class detail::worker;
+
+ typedef Channel channel;
+ typedef typename channel::item channel_item;
+
+ enum state
+ {
+ active_state,
+ terminateing_state,
+ terminated_state
+ };
+
+ struct id_idx_tag {};
+ struct rnd_idx_tag {};
+
+ typedef multi_index::multi_index_container<
+ detail::worker,
+ multi_index::indexed_by<
+ multi_index::ordered_unique<
+ multi_index::tag< id_idx_tag >,
+ multi_index::const_mem_fun<
+ detail::worker,
+ const thread::id,
+ & detail::worker::get_id
+ >
+ >,
+ multi_index::random_access< multi_index::tag< rnd_idx_tag > >
+ >
+ > worker_list;
+
+ typedef typename worker_list::template index<
+ id_idx_tag >::type id_idx;
+ typedef typename worker_list::template index<
+ rnd_idx_tag >::type rnd_idx;
+
+ class random_idx
+ {
+ private:
+ rand48 rng_;
+ uniform_int<> six_;
+ variate_generator< rand48 &, uniform_int<> > die_;
+
+ public:
+ random_idx( std::size_t size)
+ :
+ rng_(),
+ six_( 0, size - 1),
+ die_( rng_, six_)
+ {}
+
+ std::size_t operator()()
+ { return die_(); }
+ };
+
+ static thread_specific_ptr< random_idx > tss_rnd_idx_;
+
+ worker_list worker_;
+ shared_mutex mtx_worker_;
+ state state_;
+ shared_mutex mtx_state_;
+ channel channel_;
+ posix_time::time_duration asleep_;
+ scanns scns_;
+ volatile uint32_t active_worker_;
+ volatile uint32_t idle_worker_;
+ volatile uint32_t running_worker_;
+
+ void execute_(
+ detail::callable & ca,
+ detail::interrupter & intr,
+ shared_ptr< thread > const& thrd)
+ {
+ BOOST_ASSERT( ! ca.empty() );
+ detail::guard grd( active_worker_);
+ shared_ptr< void > ig(
+ static_cast< void * >( 0),
+ boost::bind(
+ & detail::interrupter::reset,
+ intr) );
+ intr.set( thrd);
+ ca();
+ ca.clear();
+ BOOST_ASSERT( ca.empty() );
+ }
+
+ void next_callable_( detail::worker & w, detail::callable & ca, detail::interrupter & intr)
+ {
+ rnd_idx & ridx( worker_.get< rnd_idx_tag >() );
+ if ( ! w.try_take( ca, intr) )
+ {
+ if ( ! channel_.try_take( ca, intr) )
+ {
+ std::size_t idx( ( * tss_rnd_idx_)() );
+ for ( std::size_t j( 0); j < worker_.size(); ++j)
+ {
+ detail::worker other( ridx[idx]);
+ if ( this_thread::get_id() == other.get_id() ) continue;
+ if ( ++idx >= worker_.size() ) idx = 0;
+ if ( other.try_steal( ca, intr) ) break;
+ }
+
+ if ( ca.empty() )
+ {
+ detail::guard grd( idle_worker_);
+ if ( shutdown_( w) ) return;
+ w.increment_scanns();
+ if ( w.scanns() >= scns_)
+ {
+ if ( size_() == idle_worker_)
+ channel_.take( ca, intr, asleep_);
+ else
+ this_thread::sleep( asleep_);
+ w.reset_scanns();
+ }
+ else
+ this_thread::yield();
+ }
+ }
+ }
+ }
+
+ void reschedule_until_( function< bool() > const& pred)
+ {
+ detail::worker * w( detail::worker::tss_get() );
+ BOOST_ASSERT( w);
+ BOOST_ASSERT( w->get_id() == this_thread::get_id() );
+ shared_ptr< thread > thrd( w->thrd() );
+ BOOST_ASSERT( thrd);
+ detail::interrupter intr;
+ detail::callable ca;
+ while ( ! pred() )
+ {
+ next_callable_( * w, ca, intr);
+ if( ! ca.empty() )
+ {
+ execute_( ca, intr, thrd);
+ w->reset_scanns();
+ }
+ }
+ }
+
+ void entry_()
+ {
+ shared_lock< shared_mutex > lk( mtx_worker_);
+ id_idx & iidx( worker_.get< id_idx_tag >() );
+ typename id_idx::iterator i( iidx.find( this_thread::get_id() ) );
+ lk.unlock();
+ BOOST_ASSERT( i != iidx.end() );
+ detail::worker::tss_reset( new detail::worker( * i) );
+
+ detail::worker * w( detail::worker::tss_get() );
+ BOOST_ASSERT( w);
+ BOOST_ASSERT( w->get_id() == this_thread::get_id() );
+ shared_ptr< thread > thrd( w->thrd() );
+ BOOST_ASSERT( thrd);
+ detail::callable ca;
+ detail::interrupter intr;
+
+ tss_rnd_idx_.reset( new random_idx( worker_.size() ) );
+
+ detail::guard grd( running_worker_);
+
+ while ( ! shutdown_( * w) )
+ {
+ next_callable_( * w, ca, intr);
+ if( ! ca.empty() )
+ {
+ execute_( ca, intr, thrd);
+ w->reset_scanns();
+ }
+ }
+ }
+
+ void create_worker_()
+ {
+ BOOST_ASSERT( ! terminateing_() && ! terminated_() );
+ worker_.insert(
+ detail::worker(
+ * this,
+ boost::bind(
+ & pool::entry_,
+ this) ) );
+ }
+
+#ifdef BOOST_BIND_WORKER_TO_PROCESSORS
+ void entry_( std::size_t n)
+ {
+ this_thread::bind_to_processor( n);
+ entry_();
+ }
+
+ void create_worker_( std::size_t n)
+ {
+ BOOST_ASSERT( ! terminateing_() && ! terminated_() );
+ worker_.insert(
+ detail::worker(
+ * this,
+ boost::bind(
+ & pool::entry_,
+ this,
+ n) ) );
+ }
+#endif
+
+ std::size_t active_() const
+ { return active_worker_; }
+
+ std::size_t idle_() const
+ { return size_() - active_(); }
+
+ std::size_t size_() const
+ { return worker_.size(); }
+
+ bool terminated_() const
+ { return state_ == terminated_state; }
+
+ bool terminateing_() const
+ { return state_ == terminateing_state; }
+
+ bool shutdown_( detail::worker & w)
+ {
+ if ( w.shutdown() && channel_.empty() )
+ return true;
+ else if ( w.shutdown_now() )
+ return true;
+ return false;
+ }
+
+public:
+ explicit pool(
+ poolsize const& psize,
+ posix_time::time_duration const& asleep = posix_time::microseconds( 10),
+ scanns const& scns = scanns( 20) )
+ :
+ worker_(),
+ mtx_worker_(),
+ state_( active_state),
+ mtx_state_(),
+ channel_(),
+ asleep_( asleep),
+ scns_( scns),
+ active_worker_( 0),
+ idle_worker_( 0),
+ running_worker_( 0)
+ {
+ if ( asleep_.is_special() || asleep_.is_negative() )
+ throw invalid_timeduration("argument asleep is not valid");
+ channel_.activate();
+ unique_lock< shared_mutex > lk( mtx_worker_);
+ for ( std::size_t i( 0); i < psize; ++i)
+ create_worker_();
+ lk.unlock();
+ }
+
+ explicit pool(
+ poolsize const& psize,
+ high_watermark const& hwm,
+ low_watermark const& lwm,
+ posix_time::time_duration const& asleep = posix_time::microseconds( 100),
+ scanns const& scns = scanns( 20) )
+ :
+ worker_(),
+ mtx_worker_(),
+ state_( active_state),
+ mtx_state_(),
+ channel_(
+ hwm,
+ lwm),
+ asleep_( asleep),
+ scns_( scns),
+ active_worker_( 0),
+ idle_worker_( 0),
+ running_worker_( 0)
+ {
+ if ( asleep_.is_special() || asleep_.is_negative() )
+ throw invalid_timeduration("argument asleep is not valid");
+ channel_.activate();
+ unique_lock< shared_mutex > lk( mtx_worker_);
+ for ( std::size_t i( 0); i < psize; ++i)
+ create_worker_();
+ lk.unlock();
+ }
+
+#ifdef BOOST_BIND_WORKER_TO_PROCESSORS
+ explicit pool(
+ posix_time::time_duration const& asleep = posix_time::microseconds( 10),
+ scanns const& scns = scanns( 20) )
+ :
+ worker_(),
+ mtx_worker_(),
+ state_( active_state),
+ mtx_state_(),
+ channel_(),
+ asleep_( asleep),
+ scns_( scns),
+ active_worker_( 0),
+ idle_worker_( 0),
+ running_worker_( 0)
+ {
+ if ( asleep_.is_special() || asleep_.is_negative() )
+ throw invalid_timeduration("argument asleep is not valid");
+ std::size_t psize( thread::hardware_concurrency() );
+ BOOST_ASSERT( psize > 0);
+ channel_.activate();
+ unique_lock< shared_mutex > lk( mtx_worker_);
+ for ( std::size_t i( 0); i < psize; ++i)
+ create_worker_( i);
+ lk.unlock();
+ }
+
+ explicit pool(
+ high_watermark const& hwm,
+ low_watermark const& lwm,
+ posix_time::time_duration const& asleep = posix_time::microseconds( 100),
+ scanns const& scns = scanns( 20) )
+ :
+ worker_(),
+ mtx_worker_(),
+ state_( active_state),
+ mtx_state_(),
+ channel_(
+ hwm,
+ lwm),
+ asleep_( asleep),
+ scns_( scns),
+ active_worker_( 0),
+ idle_worker_( 0),
+ running_worker_( 0)
+ {
+ if ( asleep_.is_special() || asleep_.is_negative() )
+ throw invalid_timeduration("argument asleep is not valid");
+ std::size_t psize( thread::hardware_concurrency() );
+ BOOST_ASSERT( psize > 0);
+ channel_.activate();
+ unique_lock< shared_mutex > lk( mtx_worker_);
+ for ( std::size_t i( 0); i < psize; ++i)
+ create_worker_( i);
+ lk.unlock();
+ }
+#endif
+
+ ~pool()
+ { shutdown(); }
+
+ std::size_t active()
+ {
+ shared_lock< shared_mutex > lk( mtx_worker_);
+ return active_();
+ }
+
+ std::size_t idle()
+ {
+ shared_lock< shared_mutex > lk( mtx_worker_);
+ return idle_();
+ }
+
+ void shutdown()
+ {
+ unique_lock< shared_mutex > lk1( mtx_state_);
+ if ( terminateing_() || terminated_() ) return;
+ state_ = terminateing_state;
+ lk1.unlock();
+
+ channel_.deactivate();
+ shared_lock< shared_mutex > lk2( mtx_worker_);
+ BOOST_FOREACH( detail::worker w, worker_)
+ { w.signal_shutdown(); }
+ BOOST_FOREACH( detail::worker w, worker_)
+ { w.join(); }
+ lk2.unlock();
+
+ lk1.lock();
+ state_ = terminated_state;
+ }
+
+ const std::vector< detail::callable > shutdown_now()
+ {
+ unique_lock< shared_mutex > lk1( mtx_state_);
+ if ( terminateing_() || terminated_() ) return std::vector< detail::callable >();
+ state_ = terminateing_state;
+ lk1.unlock();
+
+ channel_.deactivate_now();
+ shared_lock< shared_mutex > lk2( mtx_worker_);
+ BOOST_FOREACH( detail::worker w, worker_)
+ {
+ w.signal_shutdown_now();
+ w.interrupt();
+ }
+ BOOST_FOREACH( detail::worker w, worker_)
+ { w.join(); }
+ lk2.unlock();
+ std::vector< detail::callable > drain( channel_.drain() );
+
+ lk1.lock();
+ state_ = terminated_state;
+ lk1.unlock();
+
+ return drain;
+ }
+
+ std::size_t size()
+ {
+ shared_lock< shared_mutex > lk( mtx_worker_);
+ return size_();
+ }
+
+ bool terminated()
+ {
+ shared_lock< shared_mutex > lk( mtx_state_);
+ return terminated_();
+ }
+
+ bool terminateing()
+ {
+ shared_lock< shared_mutex > lk( mtx_state_);
+ return terminateing_();
+ }
+
+ void clear()
+ { channel_.clear(); }
+
+ bool empty()
+ { return channel_.empty(); }
+
+ std::size_t pending()
+ { return channel_.size(); }
+
+ std::size_t upper_bound()
+ { return channel_.upper_bound(); }
+
+ void upper_bound( high_watermark const& hwm)
+ { return channel_.upper_bound( hwm); }
+
+ std::size_t lower_bound()
+ { return channel_.lower_bound(); }
+
+ void lower_bound( low_watermark const lwm)
+ { return channel_.lower_bound( lwm); }
+
+ template< typename Act >
+ task< typename result_of< Act() >::type > submit( Act const& act)
+ {
+ typedef typename result_of< Act() >::type R;
+ detail::interrupter intr;
+ packaged_task< R > tsk( act);
+ shared_future< R > f( tsk.get_future() );
+ detail::worker * w( detail::worker::tss_get() );
+ if ( w)
+ {
+ function< bool() > wcb(
+ bind(
+ & shared_future< R >::is_ready,
+ f) );
+ tsk.set_wait_callback(
+ bind(
+ ( void ( pool::*)( function< bool() > const&) ) & pool::reschedule_until_,
+ this,
+ wcb) );
+ w->put( detail::callable( move( tsk) ), intr);
+ return task< R >( f, intr);
+ }
+ else
+ {
+ shared_lock< shared_mutex > lk( mtx_state_);
+ if ( terminated_() )
+ throw task_rejected("pool ist terminated");
+ if ( terminateing_() )
+ throw task_rejected("pool ist terminateing");
+
+ channel_item itm( detail::callable( move( tsk) ), intr);
+ channel_.put( itm);
+ return task< R >( f, intr);
+ }
+ }
+
+ template<
+ typename Act,
+ typename Attr
+ >
+ task< typename result_of< Act() >::type > submit(
+ Act const& act,
+ Attr const& attr)
+ {
+ typedef typename result_of< Act() >::type R;
+ detail::interrupter intr;
+ packaged_task< R > tsk( act);
+ shared_future< R > f( tsk.get_future() );
+ detail::worker * w( detail::worker::tss_get() );
+ if ( w)
+ {
+ function< bool() > wcb(
+ bind(
+ & shared_future< R >::is_ready,
+ f) );
+ tsk.set_wait_callback(
+ bind(
+ ( void ( pool::*)( function< bool() > const&) ) & pool::reschedule_until_,
+ this,
+ wcb) );
+ w->put( detail::callable( move( tsk) ), intr);
+ return task< R >( f, intr);
+ }
+ else
+ {
+ shared_lock< shared_mutex > lk( mtx_state_);
+ if ( terminated_() )
+ throw task_rejected("pool ist terminated");
+ if ( terminateing_() )
+ throw task_rejected("pool ist terminateing");
+
+ channel_item itm( detail::callable( move( tsk) ), attr, intr);
+ channel_.put( itm);
+ return task< R >( f, intr);
+ }
+ }
+ template< typename Pred >
+ void reschedule_until( Pred const& pred)
+ {
+ reschedule_until_(pred);
+ }
+};
+
+template< typename Channel >
+thread_specific_ptr< typename pool< Channel >::random_idx >
+pool< Channel >::tss_rnd_idx_;
+
+}}
+
+#endif // BOOST_TP_POOL_H
+
Added: sandbox/async/boost/tp/poolsize.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/poolsize.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,26 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_POOLSIZE_H
+#define BOOST_TP_POOLSIZE_H
+
+#include <cstddef>
+
+#include <boost/tp/exceptions.hpp>
+
+namespace boost { namespace tp
+{
+class poolsize
+{
+private:
+ std::size_t value_;
+
+public:
+ explicit poolsize( std::size_t value);
+
+ operator std::size_t () const;
+};
+} }
+
+#endif // BOOST_TP_POOLSIZE_H
Added: sandbox/async/boost/tp/priority.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/priority.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,130 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_PRIORITY_H
+#define BOOST_TP_PRIORITY_H
+
+#include <cstddef>
+#include <utility>
+
+#include <boost/assert.hpp>
+#include <boost/function.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+
+#include <boost/tp/detail/info.hpp>
+#include <boost/tp/detail/interrupter.hpp>
+
+namespace boost { namespace tp
+{
+template<
+ typename Attr,
+ typename Ord = std::less< Attr >
+>
+struct priority
+{
+ typedef Attr attribute_type;
+ typedef detail::has_priority priority_tag_type;
+
+ template< typename Callable >
+ class impl
+ {
+ private:
+ typedef Attr attribute;
+ typedef Callable callable;
+ typedef Ord ordering;
+
+ public:
+ class item
+ {
+ private:
+ callable ca_;
+ attribute attr_;
+ detail::interrupter intr_;
+
+ public:
+ item(
+ callable const& ca,
+ attribute const& attr,
+ detail::interrupter const& intr)
+ : ca_( ca), attr_( attr), intr_( intr)
+ { BOOST_ASSERT( ! ca_.empty() ); }
+
+ const callable ca() const
+ { return ca_; }
+
+ const attribute attr() const
+ { return attr_; }
+
+ const detail::interrupter intr() const
+ { return intr_; }
+ };
+
+ private:
+ typedef multi_index::multi_index_container<
+ item,
+ multi_index::indexed_by<
+ multi_index::ordered_non_unique<
+ multi_index::const_mem_fun<
+ item,
+ const attribute,
+ & item::attr
+ >,
+ ordering
+ >
+ >
+ > list;
+ typedef typename list::template nth_index< 0 >::type index;
+
+ list lst_;
+ index & idx_;
+
+ public:
+ typedef typename list::iterator iterator;
+ typedef typename list::const_iterator const_iterator;
+
+ impl()
+ :
+ lst_(),
+ idx_( lst_.get< 0 >() )
+ {}
+
+ void push( item const& itm)
+ { idx_.insert( itm); }
+
+ const item pop()
+ {
+ iterator i( lst_.begin() );
+ BOOST_ASSERT( i != lst_.end() );
+ item itm( * i);
+ lst_.erase( i);
+ return itm;
+ }
+
+ std::size_t size() const
+ { return lst_.size(); }
+
+ bool empty() const
+ { return lst_.empty(); }
+
+ void clear()
+ { lst_.clear(); }
+
+ const iterator begin()
+ { return lst_.begin(); }
+
+ const const_iterator begin() const
+ { return lst_.begin(); }
+
+ const iterator end()
+ { return lst_.end(); }
+
+ const const_iterator end() const
+ { return lst_.end(); }
+ };
+};
+} }
+
+#endif // BOOST_TP_PRIORITY_H
Added: sandbox/async/boost/tp/scanns.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/scanns.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,27 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_SCANNS_H
+#define BOOST_TP_SCANNS_H
+
+#include <cstddef>
+
+#include <boost/tp/exceptions.hpp>
+
+namespace boost { namespace tp
+{
+
+class scanns
+{
+private:
+ std::size_t value_;
+
+public:
+ explicit scanns( std::size_t value);
+
+ operator std::size_t () const;
+};
+} }
+
+#endif // BOOST_TP_SCANNS_H
Added: sandbox/async/boost/tp/smart.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/smart.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,174 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_SMART_H
+#define BOOST_TP_SMART_H
+
+#include <cstddef>
+
+#include <boost/assert.hpp>
+#include <boost/function.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+
+#include <boost/tp/detail/info.hpp>
+#include <boost/tp/detail/interrupter.hpp>
+
+namespace boost { namespace tp
+{
+template<
+ typename Attr,
+ typename Ord,
+ typename Enq,
+ typename Deq
+>
+struct smart
+{
+ typedef Attr attribute_type;
+ typedef detail::has_priority priority_tag_type;
+
+ template< typename Callable >
+ class impl
+ {
+ private:
+ typedef Attr attribute;
+ typedef Callable callable;
+ typedef Deq dequeue_op;
+ typedef Enq enqueue_op;
+ typedef Ord ordering;
+
+ public:
+ class item
+ {
+ private:
+ callable ca_;
+ attribute attr_;
+ detail::interrupter intr_;
+
+ public:
+ item()
+ : ca_(), attr_(), intr_()
+ {}
+
+ item(
+ callable const& ca,
+ attribute const& attr,
+ detail::interrupter const& intr)
+ : ca_( ca), attr_( attr), intr_( intr)
+ { BOOST_ASSERT( ! ca_.empty() ); }
+
+ const callable ca() const
+ { return ca_; }
+
+ const attribute attr() const
+ { return attr_; }
+
+ const detail::interrupter intr() const
+ { return intr_; }
+ };
+
+ private:
+ typedef multi_index::multi_index_container<
+ item,
+ multi_index::indexed_by<
+ multi_index::ordered_non_unique<
+ multi_index::const_mem_fun<
+ item,
+ const attribute,
+ & item::attr
+ >,
+ ordering
+ >
+ >
+ > list;
+ typedef typename list::template nth_index< 0 >::type index;
+
+ list lst_;
+ index & idx_;
+ enqueue_op enq_op_;
+ dequeue_op deq_op_;
+
+ public:
+ typedef typename index::iterator iterator;
+ typedef typename index::const_iterator const_iterator;
+
+ impl(
+ enqueue_op const& enq_op = enqueue_op(),
+ dequeue_op const& deq_op = dequeue_op() )
+ :
+ lst_(),
+ idx_( lst_.get< 0 >() ),
+ enq_op_( enq_op),
+ deq_op_( deq_op)
+ {}
+
+ void push( item const& itm)
+ { enq_op_( idx_, itm); }
+
+ const item pop()
+ {
+ item itm;
+ deq_op_( idx_, itm);
+ return itm;
+ }
+
+ std::size_t size() const
+ { return lst_.size(); }
+
+ bool empty() const
+ { return lst_.empty(); }
+
+ void clear()
+ { lst_.clear(); }
+
+ const iterator begin()
+ { return lst_.begin(); }
+
+ const const_iterator begin() const
+ { return lst_.begin(); }
+
+ const iterator end()
+ { return lst_.end(); }
+
+ const const_iterator end() const
+ { return lst_.end(); }
+ };
+};
+
+struct replace_oldest
+{
+ template<
+ typename Index,
+ typename Item
+ >
+ void operator()( Index & idx, Item const& itm)
+ {
+ typedef typename Index::iterator iterator;
+ iterator i( idx.find( itm.attr() ) );
+ if ( i == idx.end() )
+ idx.insert( itm);
+ else
+ idx.replace( i, itm);
+ }
+};
+
+struct take_oldest
+{
+ template<
+ typename Index,
+ typename Item
+ >
+ void operator()( Index & idx, Item & itm)
+ {
+ typedef typename Index::iterator iterator;
+ iterator i( idx.begin() );
+ BOOST_ASSERT( i != idx.end() );
+ itm = * i;
+ idx.erase( i);
+ }
+};
+} }
+
+#endif // BOOST_TP_SMART_H
Added: sandbox/async/boost/tp/task.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/task.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,96 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_TASK_H
+#define BOOST_TP_TASK_H
+
+#include <boost/future.hpp>
+#include <boost/thread/thread_time.hpp>
+
+#include <boost/tp/detail/interrupter.hpp>
+
+namespace boost { namespace tp
+{
+template< typename R >
+class task
+{
+private:
+ shared_future< R > fut_;
+ detail::interrupter intr_;
+
+public:
+ task()
+ : fut_(), intr_()
+ {}
+
+ task(
+ shared_future< R > const& fut,
+ detail::interrupter const& intr)
+ :
+ fut_( fut),
+ intr_( intr)
+ {}
+
+ void interrupt()
+ { intr_.interrupt(); }
+
+ void interrupt_and_wait()
+ { intr_.interrupt_and_wait(); }
+
+ void interrupt_and_wait( system_time const& abs_time)
+ { intr_.interrupt_and_wait( abs_time); }
+
+ template< typename Duration >
+ void interrupt_and_wait( Duration const& rel_time)
+ { intr_.interrupt_and_wait( rel_time); }
+
+ bool interruption_requested()
+ { return intr_.interruption_requested(); }
+
+ shared_future< R > result()
+ { return fut_; }
+};
+
+template<>
+class task< void >
+{
+private:
+ shared_future< void > fut_;
+ detail::interrupter intr_;
+
+public:
+ task()
+ : fut_(), intr_()
+ {}
+ task(
+ shared_future< void > const& fut,
+ detail::interrupter const& intr)
+ :
+ fut_( fut),
+ intr_( intr)
+ {}
+
+ void interrupt()
+ { intr_.interrupt(); }
+
+ void interrupt_and_wait()
+ { intr_.interrupt_and_wait(); }
+
+ void interrupt_and_wait( system_time const& abs_time)
+ { intr_.interrupt_and_wait( abs_time); }
+
+ template< typename Duration >
+ void interrupt_and_wait( Duration const& rel_time)
+ { intr_.interrupt_and_wait( rel_time); }
+
+ bool interruption_requested()
+ { return intr_.interruption_requested(); }
+
+ shared_future< void > result()
+ { return fut_; }
+};
+
+} }
+
+#endif // BOOST_TP_TASK_H
Added: sandbox/async/boost/tp/unbounded_channel.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/unbounded_channel.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,294 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_UNBOUNDED_CHANNEL_H
+#define BOOST_TP_UNBOUNDED_CHANNEL_H
+
+#include <cstddef>
+#include <vector>
+
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <boost/tp/detail/callable.hpp>
+#include <boost/tp/detail/interrupter.hpp>
+#include <boost/tp/exceptions.hpp>
+
+namespace boost { namespace tp
+{
+template< typename SchedulingPolicy >
+class unbounded_channel
+{
+private:
+ typedef SchedulingPolicy scheduling_policy;
+ typedef typename scheduling_policy::template impl<
+ detail::callable
+ > queue;
+
+public:
+ typedef typename queue::item item;
+ typedef scheduling_policy scheduler_type;
+
+private:
+ enum channel_state
+ {
+ channel_active,
+ channel_deactive,
+ channel_deactive_now
+ };
+
+ channel_state state_;
+ queue queue_;
+ shared_mutex mtx_;
+ condition not_empty_cond_;
+
+ bool active_() const
+ { return state_ == channel_active; }
+
+ bool deactive_() const
+ { return state_ == channel_deactive; }
+
+ bool deactive_now_() const
+ { return state_ == channel_deactive_now; }
+
+ void activate_()
+ { state_ = channel_active; }
+
+ void clear_()
+ {
+ BOOST_ASSERT( ! active_() );
+ queue_.clear();
+ BOOST_ASSERT( empty_() );
+ }
+
+ void deactivate_()
+ {
+ if ( active_() )
+ {
+ state_ = channel_deactive;
+ not_empty_cond_.notify_all();
+ }
+
+ BOOST_ASSERT( deactive_() );
+ }
+
+ void deactivate_now_()
+ {
+ if ( active_() )
+ {
+ state_ = channel_deactive_now;
+ not_empty_cond_.notify_all();
+ }
+
+ BOOST_ASSERT( deactive_now_() );
+ }
+
+ const std::vector< detail::callable > drain_()
+ {
+ BOOST_ASSERT( deactive_now_() );
+ std::vector< detail::callable > unprocessed;
+ unprocessed.reserve( queue_.size() );
+ BOOST_FOREACH( item itm, queue_)
+ { unprocessed.push_back( itm.ca() ); }
+ clear_();
+ BOOST_ASSERT( empty_() );
+ return unprocessed;
+ }
+
+ bool empty_() const
+ { return queue_.empty(); }
+
+ std::size_t size_() const
+ { return queue_.size(); }
+
+ void put_(
+ item const& itm,
+ unique_lock< shared_mutex > & lk)
+ {
+ queue_.push( itm);
+ not_empty_cond_.notify_one();
+ }
+
+ bool take_(
+ detail::callable & ca,
+ detail::interrupter & intr,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( deactive_now_() || ( deactive_() && empty_() ) )
+ return false;
+ try
+ {
+ not_empty_cond_.wait(
+ lk,
+ bind(
+ & unbounded_channel::consumers_activate_,
+ this) );
+ }
+ catch ( thread_interrupted const& e)
+ { return false; }
+ if ( deactive_now_() || ( deactive_() && empty_() ) )
+ return false;
+ item itm( queue_.pop() );
+ ca = itm.ca();
+ intr = itm.intr();
+ return ! ca.empty();
+ }
+
+ template< typename Duration >
+ bool take_(
+ detail::callable & ca,
+ detail::interrupter & intr,
+ Duration const& rel_time,
+ unique_lock< shared_mutex > & lk)
+ {
+ if ( deactive_now_() || ( deactive_() && empty_() ) )
+ return false;
+ try
+ {
+ if ( ! not_empty_cond_.timed_wait(
+ lk,
+ rel_time,
+ bind(
+ & unbounded_channel::consumers_activate_,
+ this) ) )
+ return false;
+ }
+ catch ( thread_interrupted const& e)
+ { return false; }
+ if ( deactive_now_() || ( deactive_() && empty_() ) )
+ return false;
+ item itm( queue_.pop() );
+ ca = itm.ca();
+ intr = itm.intr();
+ return ! ca.empty();
+ }
+
+ bool try_take_(
+ detail::callable & ca,
+ detail::interrupter & intr)
+ {
+ if ( deactive_now_() || empty_() )
+ return false;
+ item itm( queue_.pop() );
+ ca = itm.ca();
+ intr = itm.intr();
+ return ! ca.empty();
+ }
+
+ bool consumers_activate_() const
+ { return ! active_() || ! empty_(); }
+
+public:
+ unbounded_channel()
+ :
+ state_( channel_active),
+ queue_(),
+ mtx_(),
+ not_empty_cond_()
+ {}
+
+ bool active()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return active_();
+ }
+
+ void activate()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ activate_();
+ }
+
+ void clear()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ clear_();
+ }
+
+ bool deactive()
+ { return ! active(); }
+
+ void deactivate()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ deactivate_();
+ }
+
+ void deactivate_now()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ deactivate_now_();
+ }
+
+ const std::vector< detail::callable > drain()
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return drain_();
+ }
+
+ bool empty()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return empty_();
+ }
+
+ bool full()
+ { return false; }
+
+ std::size_t size()
+ {
+ shared_lock< shared_mutex > lk( mtx_);
+ return size_();
+ }
+
+ void put( item const& itm)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( itm, lk);
+ }
+
+ template< typename Duration >
+ void put(
+ item const& itm,
+ Duration const&)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ put_( itm, lk);
+ }
+
+ bool take(
+ detail::callable & ca,
+ detail::interrupter & intr)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, intr, lk);
+ }
+
+ template< typename Duration >
+ bool take(
+ detail::callable & ca,
+ detail::interrupter & intr,
+ Duration const& rel_time)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return take_( ca, intr, rel_time, lk);
+ }
+
+ bool try_take(
+ detail::callable & ca,
+ detail::interrupter & intr)
+ {
+ unique_lock< shared_mutex > lk( mtx_);
+ return try_take_( ca, intr);
+ }
+};
+} }
+
+#endif // BOOST_TP_UNBOUNDED_CHANNEL_H
Added: sandbox/async/boost/tp/watermark.hpp
==============================================================================
--- (empty file)
+++ sandbox/async/boost/tp/watermark.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,37 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_WATER_MARK_H
+#define BOOST_TP_WATER_MARK_H
+
+#include <cstddef>
+
+#include <boost/tp/exceptions.hpp>
+
+namespace boost { namespace tp
+{
+class high_watermark
+{
+private:
+ std::size_t value_;
+
+public:
+ explicit high_watermark( std::size_t value);
+
+ operator std::size_t () const;
+};
+
+class low_watermark
+{
+private:
+ std::size_t value_;
+
+public:
+ explicit low_watermark( std::size_t value);
+
+ operator std::size_t () const;
+};
+} }
+
+#endif // BOOST_TP_WATER_MARK_H
Added: sandbox/async/libs/tp/build/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/build/Jamfile.v2 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,29 @@
+# Boost System Library Build Jamfile
+
+# (C) Copyright Oliver Kowalke 2009
+
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or www.boost.org/LICENSE_1_0.txt)
+
+# See library home page at http://www.boost.org/libs/system
+
+project boost/tp
+ : source-location ../src
+ : requirements
+ <include>../../..
+ <include>$(BOOST_ROOT)
+
+ : usage-requirements # pass these requirement to dependents (i.e. users)
+ <link>shared:<define>BOOST_THREADPOOL_DYN_LINK=1
+ <link>static:<define>BOOST_THREADPOOL_STATIC_LINK=1
+ ;
+
+SOURCES = callable default_pool guard interrupter poolsize scanns watermark worker ;
+
+static-lib boost_threadpool
+ : $(SOURCES).cpp
+ : #<link>shared:<define>BOOST_THREADPOOL_DYN_LINK=1
+ <link>static:<define>BOOST_THREADPOOL_STATIC_LINK=1
+ ;
+
+#boost-install boost_threadpool ;
Added: sandbox/async/libs/tp/doc/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/Jamfile.v2 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,12 @@
+# Boost.ThreadPool Library Documentation Jamfile
+
+# Copyright (C) 2008 Oliver Kowalke
+
+# Use, modification and distribution is subject to 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)
+
+using quickbook ;
+
+xml threadpool : threadpool.qbk ;
+boostbook standalone : threadpool ;
Added: sandbox/async/libs/tp/doc/acknowledgement.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/acknowledgement.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,11 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:acknowledgement Acknowledgements]
+I'd like to thank Vincente Botet Escriba for his comments on the implementation details of the code and
+Anthony Williams and Braddock Gaskill for their future libraries.
+[endsect]
Added: sandbox/async/libs/tp/doc/channel.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/channel.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,30 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:channel Channel]
+The channel synchronizes the access between application threads (producer threads) submitting __actions__ to the pool and __worker_threads__ (consumer threads). The scheduling of __actions__ queued into the channel depends on channels the scheduling policy.
+If the channel becomes empty all __worker_threads__ are set to sleep until a new __action__ is put in.
+
+[heading bounded channel]
+
+ template< typename SchedulingPolicy > class bounded_channel
+
+The number of pending __actions__ is limited in order to prevent resource exhaustion. For this purpose a high and low watermark has to be passed at construction.
+`boost::tp::high_watermark` sets the maximum of pending tasks. If this limited is reached all threads which submit a tasks will be set to sleep (blocked).
+`boost::tp::low_watermark` sets the threshold when blocked threads get woken up.
+If __hwm__ is equal to __lwm__ everytime a sleeping producer thread will be woken up and puts
+its task if one worker thread has taken a task from the channel.
+If __lwm__ is less than __hwm__ all sleeping producer threads will be woken up if
+the amount of pending tasks reaches __lwm__.
+
+[heading unbounded channel]
+
+ template< typename SchedulingPolicy > class unbounded_channel
+
+An unlimited number of __actions__ can be queued into this channel. The insertion of __actions__ will never block. If the channel becomes empty __worker_threads__ will be set to sleep until new __actions__ are inserted into the channel.
+
+[endsect]
Added: sandbox/async/libs/tp/doc/exceptions_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/exceptions_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,126 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:invalid_poolsize Class `invalid_poolsize`]
+
+ #include <boost/tp/exceptions.hpp>
+
+ class invalid_poolsize
+ : public std::invalid_argument
+ {
+ public:
+ invalid_poolsize( std::string const& msg);
+ };
+
+[section:constructor Constructor]
+
+ invalid_poolsize( std::string const& msg);
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::invalid_poolsize` instance.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
+
+
+[section:invalid_scanns Class `invalid_scanns`]
+
+ #include <boost/tp/exceptions.hpp>
+
+ class invalid_scanns
+ : public std::invalid_argument
+ {
+ public:
+ invalid_scanns( std::string const& msg);
+ };
+
+[section:constructor Constructor]
+
+ invalid_scanns( std::string const& msg);
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::invalid_scanns` instance.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
+
+
+[section:invalid_timeduration Class `invalid_timeduration`]
+
+ #include <boost/tp/exceptions.hpp>
+
+ class invalid_timeduration
+ : public std::invalid_argument
+ {
+ public:
+ invalid_timeduration( std::string const& msg);
+ };
+
+[section:constructor Constructor]
+
+ invalid_timeduration( std::string const& msg);
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::invalid_timeduration` instance.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
+
+
+[section:invalid_watermark Class `invalid_watermark`]
+
+ #include <boost/tp/exceptions.hpp>
+
+ class invalid_watermark
+ : public std::invalid_argument
+ {
+ public:
+ invalid_watermark( std::string const& msg);
+ };
+
+[section:constructor Constructor]
+
+ invalid_watermark( std::string const& msg);
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::invalid_watermark` instance.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
+
+
+[section:task_rejected Class `task_rejected`]
+
+ #include <boost/tp/exceptions.hpp>
+
+ class task_rejected
+ : public std::runtime_error
+ {
+ public:
+ task_rejected( std::string const& msg);
+ };
+
+[section:constructor Constructor]
+
+ task_rejected( std::string const& msg);
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::task_rejected` instance.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
+
Added: sandbox/async/libs/tp/doc/forkjoin.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/forkjoin.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,102 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:forkjoin Fork/Join]
+Fork/Join algorithms are recursive divide-and-conquer algorithms which repeatedly splitt __sub_actions__ until they become small enough to solve using simple, short sequential methods, so that they run in parallel on multiple cores.
+
+The fork operation creates a new __sub_action__ (which can run in parallel) in the pool. The current __actions__ is not proceeded in the join operation until the forked __sub_actions__ have completed. In the meantime the __worker_thread__ executes other __actions__ from its local __worker_queue__.
+
+ // defines the threadpool type
+ namespace pt = boost::posix_time;
+ namespace tp = boost::tp;
+
+ typedef tp::pool< tp::unbounded_channel< tp::fifo > > pool_type;
+
+ class fibo
+ {
+ private:
+ int offset_;
+
+ int seq_( int n)
+ {
+ if ( n <= 1) return n;
+ else return seq_( n - 2) + seq_( n - 1);
+ }
+
+ int par_( int n)
+ {
+ if ( n <= offset_) return seq_( n);
+ else
+ {
+ tp::task< int > t1(
+ boost::this_task::get_thread_pool< pool_type >().submit(
+ boost::bind(
+ & fibo::par_,
+ boost::ref( * this),
+ n - 1) ) );
+ tp::task< int > t2(
+ boost::this_task::get_thread_pool< pool_type >().submit(
+ boost::bind(
+ & fibo::par_,
+ boost::ref( * this),
+ n - 2) ) );
+ return t1.result().get() + t2.result().get();
+ }
+ }
+
+ public:
+ fibo( int offset)
+ : offset_( offset)
+ {}
+
+ int execute( int n)
+ {
+ int result( par_( n) );
+ return result;
+ }
+ };
+
+ int main( int argc, char *argv[])
+ {
+ try
+ {
+ pool_type pool( tp::poolsize( 3) );
+ fibo fib( 5);
+ std::vector< tp::task< int > > results;
+ results.reserve( 40);
+
+ pt::ptime start( pt::microsec_clock::universal_time() );
+
+ for ( int i = 0; i < 32; ++i)
+ results.push_back(
+ pool.submit(
+ boost::bind(
+ & fibo::execute,
+ boost::ref( fib),
+ i) ) );
+
+ int k = 0;
+ std::vector< tp::task< int > >::iterator e( results.end() );
+ for (
+ std::vector< tp::task< int > >::iterator i( results.begin() );
+ i != e;
+ ++i)
+ std::cout << "fibonacci " << k++ << " == " << i->result().get() << std::endl;
+
+ pt::ptime stop( pt::microsec_clock::universal_time() );
+ std::cout << ( stop - start).total_milliseconds() << " milli seconds" << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+ }
+[endsect]
Added: sandbox/async/libs/tp/doc/html/boost_threadpool/acknowledgement.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/boost_threadpool/acknowledgement.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,48 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Acknowledgements</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="prev" href="forkjoin.html" title="Fork/Join">
+<link rel="next" href="reference.html" title="Reference">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="forkjoin.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.acknowledgement"></a><a class="link" href="acknowledgement.html" title="Acknowledgements"> Acknowledgements</a>
+</h2></div></div></div>
+<p>
+ I'd like to thank Vincente Botet Escriba for his comments on the implementation
+ details of the code and Anthony Williams and Braddock Gaskill for their future
+ libraries.
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Oliver Kowalke<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="forkjoin.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/html/boost_threadpool/channel.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/boost_threadpool/channel.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,79 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Channel</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="prev" href="this_task.html" title="Namespace this_task">
+<link rel="next" href="scheduling.html" title="Scheduling">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="this_task.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="scheduling.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.channel"></a><a class="link" href="channel.html" title="Channel"> Channel</a>
+</h2></div></div></div>
+<p>
+ The channel synchronizes the access between application threads (producer threads)
+ submitting actions to the pool and worker threads (consumer threads). The scheduling
+ of actions queued into the channel depends on channels the scheduling policy.
+ If the channel becomes empty all worker threads are set to sleep until a new
+ action is put in.
+ </p>
+<a name="boost_threadpool.channel.bounded_channel"></a><h4>
+<a name="id372246"></a>
+ <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel">bounded channel</a>
+ </h4>
+<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">SchedulingPolicy</span> <span class="special">></span> <span class="keyword">class</span> <span class="identifier">bounded_channel</span>
+</pre>
+<p>
+ The number of pending actions is limited in order to prevent resource exhaustion.
+ For this purpose a high and low watermark has to be passed at construction.
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">high_watermark</span></code>
+ sets the maximum of pending tasks. If this limited is reached all threads which
+ submit a tasks will be set to sleep (blocked). <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">low_watermark</span></code> sets the threshold when blocked
+ threads get woken up. If high watermark is equal to low watermark everytime
+ a sleeping producer thread will be woken up and puts its task if one worker
+ thread has taken a task from the channel. If low watermark is less than high
+ watermark all sleeping producer threads will be woken up if the amount of pending
+ tasks reaches low watermark.
+ </p>
+<a name="boost_threadpool.channel.unbounded_channel"></a><h4>
+<a name="id372359"></a>
+ <a class="link" href="channel.html#boost_threadpool.channel.unbounded_channel">unbounded channel</a>
+ </h4>
+<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">SchedulingPolicy</span> <span class="special">></span> <span class="keyword">class</span> <span class="identifier">unbounded_channel</span>
+</pre>
+<p>
+ An unlimited number of actions can be queued into this channel. The insertion
+ of actions will never block. If the channel becomes empty worker threads will
+ be set to sleep until new actions are inserted into the channel.
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Oliver Kowalke<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="this_task.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="scheduling.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/html/boost_threadpool/forkjoin.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/boost_threadpool/forkjoin.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,773 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Fork/Join</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="prev" href="scheduling.html" title="Scheduling">
+<link rel="next" href="acknowledgement.html" title="Acknowledgements">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="scheduling.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgement.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.forkjoin"></a><a class="link" href="forkjoin.html" title="Fork/Join"> Fork/Join</a>
+</h2></div></div></div>
+<p>
+ Fork/Join algorithms are recursive divide-and-conquer algorithms which repeatedly
+ splitt sub_actions until they become small enough to solve using simple, short
+ sequential methods, so that they run in parallel on multiple cores.
+ </p>
+<p>
+ The fork operation creates a new sub_action (which can run in parallel) in
+ the pool. The current actions is not proceeded in the join operation until
+ the forked sub_actions have completed. In the meantime the worker thread executes
+ other actions from its local <a class="link" href="pool.html#boost_threadpool.pool.work_stealing"><span class="emphasis"><em>worker
+ queue</em></span></a>.
+ </p>
+<pre class="programlisting"> <span class="comment">// defines the threadpool type
+</span> <span class="keyword">namespace</span> <span class="identifier">pt</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">;</span>
+<span class="keyword">namespace</span> <span class="identifier">tp</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">;</span>
+
+<span class="keyword">typedef</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span> <span class="special">></span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="keyword">class</span> <span class="identifier">fibo</span>
+<span class="special">{</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">offset_</span><span class="special">;</span>
+
+ <span class="keyword">int</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">n</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="keyword">int</span> <span class="identifier">par_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="identifier">offset_</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span>
+ <span class="special">{</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">t1</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">t2</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">fibo</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">offset_</span><span class="special">(</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">{}</span>
+
+ <span class="keyword">int</span> <span class="identifier">execute</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">result</span><span class="special">(</span> <span class="identifier">par_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[])</span>
+<span class="special">{</span>
+ <span class="keyword">try</span>
+ <span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">3</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">fibo</span> <span class="identifier">fib</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span> <span class="number">40</span><span class="special">);</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ // defines the threadpool type namespace pt = boost::posix_time; namespace
+ tp = boost::tp;
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span> <span class="special">></span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="keyword">class</span> <span class="identifier">fibo</span>
+<span class="special">{</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">offset_</span><span class="special">;</span>
+
+ <span class="keyword">int</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">n</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="keyword">int</span> <span class="identifier">par_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="identifier">offset_</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span>
+ <span class="special">{</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">t1</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">t2</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">fibo</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">offset_</span><span class="special">(</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">{}</span>
+
+ <span class="keyword">int</span> <span class="identifier">execute</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">result</span><span class="special">(</span> <span class="identifier">par_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[])</span>
+<span class="special">{</span>
+ <span class="keyword">try</span>
+ <span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">3</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">fibo</span> <span class="identifier">fib</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span> <span class="number">40</span><span class="special">);</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ typedef tp::pool< tp::unbounded_channel< tp::fifo > > pool_type;
+ </p>
+<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">fibo</span>
+<span class="special">{</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">offset_</span><span class="special">;</span>
+
+ <span class="keyword">int</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">n</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="keyword">int</span> <span class="identifier">par_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="identifier">offset_</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span>
+ <span class="special">{</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">t1</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">t2</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">fibo</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">offset_</span><span class="special">(</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">{}</span>
+
+ <span class="keyword">int</span> <span class="identifier">execute</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">result</span><span class="special">(</span> <span class="identifier">par_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[])</span>
+<span class="special">{</span>
+ <span class="keyword">try</span>
+ <span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">3</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">fibo</span> <span class="identifier">fib</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span> <span class="number">40</span><span class="special">);</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ class fibo { private: int offset_;
+ </p>
+<pre class="programlisting"> <span class="keyword">int</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">n</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="keyword">int</span> <span class="identifier">par_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="identifier">offset_</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span>
+ <span class="special">{</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">t1</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">t2</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">fibo</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">offset_</span><span class="special">(</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">{}</span>
+
+ <span class="keyword">int</span> <span class="identifier">execute</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">result</span><span class="special">(</span> <span class="identifier">par_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[])</span>
+<span class="special">{</span>
+ <span class="keyword">try</span>
+ <span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">3</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">fibo</span> <span class="identifier">fib</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span> <span class="number">40</span><span class="special">);</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ int seq<span class="underline">( int n) { if ( n <= 1) return n; else
+ return seq</span>( n - 2) + seq_( n - 1); }
+ </p>
+<pre class="programlisting"> <span class="keyword">int</span> <span class="identifier">par_</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special"><=</span> <span class="identifier">offset_</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">seq_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span>
+ <span class="special">{</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>().</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">par_</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="special">*</span> <span class="keyword">this</span><span class="special">),</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">t1</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">t2</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">fibo</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">offset_</span><span class="special">(</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">{}</span>
+
+ <span class="keyword">int</span> <span class="identifier">execute</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">result</span><span class="special">(</span> <span class="identifier">par_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[])</span>
+<span class="special">{</span>
+ <span class="keyword">try</span>
+ <span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">3</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">fibo</span> <span class="identifier">fib</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span> <span class="number">40</span><span class="special">);</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ int par<span class="underline">( int n) { if ( n <= offset</span>)
+ return seq_( n); else { tp::task< int > t1( boost::this_task::get_thread_pool<
+ pool<span class="underline">type >().submit( boost::bind( & fibo::par</span>,
+ boost::ref( * this), n - 1) ) ); tp::task< int > t2( boost::this_task::get_thread_pool<
+ pool<span class="underline">type >().submit( boost::bind( & fibo::par</span>,
+ boost::ref( * this), n - 2) ) ); return t1.result().get() + t2.result().get();
+ } }
+ </p>
+<pre class="programlisting"><span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">fibo</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">offset_</span><span class="special">(</span> <span class="identifier">offset</span><span class="special">)</span>
+ <span class="special">{}</span>
+
+ <span class="keyword">int</span> <span class="identifier">execute</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">result</span><span class="special">(</span> <span class="identifier">par_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[])</span>
+<span class="special">{</span>
+ <span class="keyword">try</span>
+ <span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">3</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">fibo</span> <span class="identifier">fib</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span> <span class="number">40</span><span class="special">);</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ public: fibo( int offset) : offset_( offset) {}
+ </p>
+<pre class="programlisting"> <span class="keyword">int</span> <span class="identifier">execute</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">result</span><span class="special">(</span> <span class="identifier">par_</span><span class="special">(</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[])</span>
+<span class="special">{</span>
+ <span class="keyword">try</span>
+ <span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">3</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">fibo</span> <span class="identifier">fib</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span> <span class="number">40</span><span class="special">);</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ int execute( int n) { int result( par_( n) ); return result; } };
+ </p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[])</span>
+<span class="special">{</span>
+ <span class="keyword">try</span>
+ <span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">3</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">fibo</span> <span class="identifier">fib</span><span class="special">(</span> <span class="number">5</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">reserve</span><span class="special">(</span> <span class="number">40</span><span class="special">);</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ int main( int argc, char *argv[]) { try { pool_type pool( tp::poolsize( 3)
+ ); fibo fib( 5); std::vector< tp::task< int > > results; results.reserve(
+ 40);
+ </p>
+<pre class="programlisting"> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ pt::ptime start( pt::microsec_clock::universal_time() );
+ </p>
+<pre class="programlisting"> <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">32</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="special">&</span> <span class="identifier">fibo</span><span class="special">::</span><span class="identifier">execute</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span> <span class="identifier">fib</span><span class="special">),</span>
+ <span class="identifier">i</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ for ( int i = 0; i < 32; ++i) results.push_back( pool.submit( boost::bind(
+ & fibo::execute, boost::ref( fib), i) ) );
+ </p>
+<pre class="programlisting"> <span class="keyword">int</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">e</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">>::</span><span class="identifier">iterator</span> <span class="identifier">i</span><span class="special">(</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">e</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"fibonacci "</span> <span class="special"><<</span> <span class="identifier">k</span><span class="special">++</span> <span class="special"><<</span> <span class="string">" == "</span> <span class="special"><<</span> <span class="identifier">i</span><span class="special">-></span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ int k = 0; std::vector< tp::task< int > >::iterator e( results.end()
+ ); for ( std::vector< tp::task< int > >::iterator i( results.begin()
+ ); i != e; ++i) std::cout << "fibonacci " << k++ <<
+ " == " << i->result().get() << std::endl;
+ </p>
+<pre class="programlisting"> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">ptime</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">pt</span><span class="special">::</span><span class="identifier">microsec_clock</span><span class="special">::</span><span class="identifier">universal_time</span><span class="special">()</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">(</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">).</span><span class="identifier">total_milliseconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milli seconds"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ pt::ptime stop( pt::microsec_clock::universal_time() ); std::cout <<
+ ( stop - start).total_milliseconds() << " milli seconds" <<
+ std::endl;
+ </p>
+<pre class="programlisting"> <span class="keyword">return</span> <span class="identifier">EXIT_SUCCESS</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"exception: "</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">catch</span> <span class="special">(</span> <span class="special">...</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cerr</span> <span class="special"><<</span> <span class="string">"unhandled"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr <<
+ "exception: " << e.what() << std::endl; } catch ( ...
+ ) { std::cerr << "unhandled" << std::endl; }
+ </p>
+<pre class="programlisting"> <span class="keyword">return</span> <span class="identifier">EXIT_FAILURE</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ return EXIT_FAILURE; }
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Oliver Kowalke<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="scheduling.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgement.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/html/boost_threadpool/pool.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/boost_threadpool/pool.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,294 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Pool</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="prev" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="next" href="task.html" title="Task">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="../index.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.pool"></a><a class="link" href="pool.html" title="Pool"> Pool</a>
+</h2></div></div></div>
+<p>
+ The pool manages internaly worker threads and submitted actions are stored
+ in a <a class="link" href="channel.html" title="Channel"><span class="emphasis"><em>channel</em></span></a>
+ (<a class="link" href="pool.html#boost_threadpool.pool.work_stealing"><span class="emphasis"><em>global queue</em></span></a>)
+ for processing by the worker threads (using a <a class="link" href="pool.html#boost_threadpool.pool.work_stealing"><span class="emphasis"><em>work
+ stealing</em></span></a> algorithm). Each submitted action gets associated
+ with a <a class="link" href="task.html" title="Task"><span class="emphasis"><em>task</em></span></a>
+ object that will be returned. The <a class="link" href="task.html" title="Task"><span class="emphasis"><em>task</em></span></a>
+ object acts as a proxy for a result that is initially not known and gets evaluated
+ later by a worker thread.
+ </p>
+<a name="boost_threadpool.pool.work_stealing"></a><h4>
+<a name="id326427"></a>
+ <a class="link" href="pool.html#boost_threadpool.pool.work_stealing">Work-Stealing</a>
+ </h4>
+<p>
+ Traditional thread poola do not scale because they use a single global queue
+ protected by a global lock. The frequency at which worker threads aquire the
+ global lock becomes a limiting factor for the throughput if:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ the actions become smaller
+ </li>
+<li>
+ more processors are added
+ </li>
+</ul></div>
+<p>
+ A work-stealing algorithm can be used to solve this problem. It uses a special
+ kind of queue which has two ends, and allows lock-free pushes and pops from
+ the <span class="emphasis"><em>private end</em></span> (accessed by the worker thread owning
+ the queue), but requires synchronization from the <span class="emphasis"><em>public end</em></span>
+ (accessed by the other worker threads). Synchronization is necessary when the
+ queue is sufficiently small that private and public operations could conflict.
+ </p>
+<p>
+ The pool contains one global queue (<a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a> or <a class="link" href="channel.html#boost_threadpool.channel.unbounded_channel"><span class="emphasis"><em>unbounded
+ channel</em></span></a>) protected by a global lock and each worker thread
+ has its own private worker queue. If work is enqueued by a worker thread the
+ action is stored in the worker queue. If the work is enqueued by a application
+ thread it goes into the global queue. When worker threads are looking for work,
+ they have following search order:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ look into the private worker queue - actions can be dequeued without locks
+ </li>
+<li>
+ look in the global queue - locks are used for synchronization
+ </li>
+<li>
+ check other worker queues ('stealing' actions from private worker queues
+ of other worker threads) - requires locks
+ </li>
+</ul></div>
+<p>
+ For a lot of recursively queued actions, the use of a worker queue per thread
+ substantially reduces the synchronization necessary to complete the work. There
+ are also fewer cache effects due to sharing of the global queue information.
+ </p>
+<p>
+ Operations on the private worker queue are executed in LIFO order and operations
+ on worker queues of other worker threads in FIFO order (steals).
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ There are chances that memory is still hot in the cache, if the actions are
+ pushed in LIFO order into the private worker queue.
+ </li>
+<li>
+ If a worker thread steals work in FIFO order, increases the chances that
+ a larger 'chunk' of work will be stolen (the need for other steals will be
+ possibly reduced). Because the actions are stored in LIFO order, the oldest
+ items are closer to the <span class="emphasis"><em>public end</em></span> of the queue (forming
+ a tree). Stealing such an older action also steals a (probably) larger subtree
+ of actions unfolded if the stolen work item get executed.
+ </li>
+</ul></div>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Actions submitted by a worker thread are stored into its private worker queue
+ in LIFO order, thatswhy priorities and timeouts specified at the submit-function
+ get ignored.
+ </p></td></tr>
+</table></div>
+<div class="important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../doc/html/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Because of the work-stealing algorithm the execution order of actions may
+ be not strict as in the global queue.
+ </p></td></tr>
+</table></div>
+<a name="boost_threadpool.pool.creation"></a><h4>
+<a name="id367654"></a>
+ <a class="link" href="pool.html#boost_threadpool.pool.creation">Creation</a>
+ </h4>
+<p>
+ The first template argument specifies the channel type and the scheduling policy.
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">6</span><span class="special">),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span> <span class="number">50</span><span class="special">),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">scanns</span><span class="special">(</span><span class="number">10</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ In the example above a thread pool is created with a <a class="link" href="channel.html#boost_threadpool.channel.unbounded_channel"><span class="emphasis"><em>unbounded
+ channel</em></span></a>, scheduling actions in <span class="emphasis"><em>FIFO</em></span>
+ order. The pool contains six worker threads going to sleep for 50 millisec
+ after 10 iterations without geting an action from the <a class="link" href="pool.html#boost_threadpool.pool.work_stealing"><span class="emphasis"><em>global
+ queue</em></span></a>, from its local <a class="link" href="pool.html#boost_threadpool.pool.work_stealing"><span class="emphasis"><em>worker
+ queue</em></span></a> or local queues of other worker threads.
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">bounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">priority</span> <span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">10</span><span class="special">),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">high_watermark</span><span class="special">(</span> <span class="number">10</span><span class="special">),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">low_watermark</span><span class="special">(</span> <span class="number">5</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ This pool uses a <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a> which schedules actions by integer atrributes. A
+ maximum of 10 actions can be queued in the <a class="link" href="pool.html#boost_threadpool.pool.work_stealing"><span class="emphasis"><em>global
+ queue</em></span></a> without blocking the inserting thread.
+ </p>
+<a name="boost_threadpool.pool.shutdown"></a><h4>
+<a name="id368155"></a>
+ <a class="link" href="pool.html#boost_threadpool.pool.shutdown">Shutdown</a>
+ </h4>
+<p>
+ If <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">Channel</span> <span class="special">>::</span><span class="identifier">shutdown</span><span class="special">()</span></code> is called - the the status of the pool is
+ set to <span class="emphasis"><em>terminating</em></span> and all worker threads are joined.
+ No futher actions can be submitted by application threads. After all pending
+ actions are processed and all worker threads are joined, the pool is set to
+ status <span class="emphasis"><em>terminated</em></span>.
+ </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ The deconstructor calls <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">Channel</span> <span class="special">>::</span><span class="identifier">shutdown</span><span class="special">()</span></code>
+ if the pool was not shutdown yet.
+ </p></td></tr>
+</table></div>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">1</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t1</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">fibonacci_fn</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t2</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">fibonacci_fn</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+<span class="identifier">pool</span><span class="special">.</span><span class="identifier">shutdown</span><span class="special">();</span>
+
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">t1</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 55
+</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">t2</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 55
+</span></pre>
+<a name="boost_threadpool.pool.shutdown_immediatly"></a><h4>
+<a name="id368800"></a>
+ <a class="link" href="pool.html#boost_threadpool.pool.shutdown_immediatly">Shutdown immediatly</a>
+ </h4>
+<p>
+ The function <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">Channel</span> <span class="special">>::</span><span class="identifier">shutdown_now</span><span class="special">()</span></code> sets the pool status to <span class="emphasis"><em>terminating</em></span>
+ interrupts and then joins all worker threads. After the worker threads are
+ joined the status of the pool is set to <span class="emphasis"><em>terminated</em></span> and
+ all pending (unprocessed) actions will be returned.
+ </p>
+<div class="important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../doc/html/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Pending actions in the local <a class="link" href="pool.html#boost_threadpool.pool.work_stealing"><span class="emphasis"><em>worker
+ queues</em></span></a> are not returned if <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">Channel</span> <span class="special">>::</span><span class="identifier">shutdown_now</span><span class="special">()</span></code>
+ was called.
+ </p></td></tr>
+</table></div>
+<a name="boost_threadpool.pool.default_pool"></a><h4>
+<a name="id368934"></a>
+ <a class="link" href="pool.html#boost_threadpool.pool.default_pool">Default pool</a>
+ </h4>
+<p>
+ The free function <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">get_default_pool</span><span class="special">()</span></code> returns a reference to the default thread
+ pool instance. The default thread pool is of type <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span> <span class="special">></span></code> and will contain as many worker threads
+ as <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">hardware_concurrency</span><span class="special">()</span></code>
+ returns.
+ </p>
+<a name="boost_threadpool.pool.meta_functions"></a><h4>
+<a name="id369097"></a>
+ <a class="link" href="pool.html#boost_threadpool.pool.meta_functions">Meta functions</a>
+ </h4>
+<p>
+ If the thread pool supports priorities <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">has_priority</span><span class="special"><</span>
+ <span class="identifier">pool_type</span> <span class="special">></span></code>
+ evaluates to <code class="computeroutput"><span class="keyword">true</span></code>. The priority
+ type is determined by <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">priority_type</span><span class="special"><</span>
+ <span class="identifier">pool_type</span> <span class="special">></span></code>.
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">priority</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">has_priority</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>::</span><span class="identifier">value</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="keyword">typeid</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">priority_type</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>::</span><span class="identifier">type</span><span class="special">).</span><span class="identifier">name</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+</pre>
+<p>
+ The support of fibers can be tested with meta-function <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">has_fibers</span><span class="special"><</span>
+ <span class="identifier">pool_type</span> <span class="special">></span></code>.
+ </p>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">has_fibers</span><span class="special"><</span> <span class="identifier">pool_type</span> <span class="special">>::</span><span class="identifier">value</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+</pre>
+<a name="boost_threadpool.pool.processor_binding"></a><h4>
+<a name="id369670"></a>
+ <a class="link" href="pool.html#boost_threadpool.pool.processor_binding">Processor binding</a>
+ </h4>
+<p>
+ For some applications it is convenient to bind the worker threads of the pool
+ to processors of the system. For this purpose BOOST_BIND_WORKER_TO_PROCESSORS
+ must be defined. Without the poolsize in the construtor the thread pool will
+ contain as many worker threads as processors (== boost::thread::hardware_concurrency)
+ are available and each worker thread is bound to one processor.
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span>
+ <span class="special">></span> <span class="identifier">pool</span><span class="special">;</span>
+</pre>
+<p>
+ The code above will create a pool with two worker threads on a dual core system
+ (each bound to one core).
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Oliver Kowalke<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="../index.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/html/boost_threadpool/reference.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/boost_threadpool/reference.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,1550 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Reference</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="prev" href="acknowledgement.html" title="Acknowledgements">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="acknowledgement.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.reference"></a><a class="link" href="reference.html" title="Reference"> Reference</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"> Class template pool
</span></dt>
+<dt><span class="section"> Class template task
</span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.reschedule_until"> Non-member
+ function <code class="computeroutput"><span class="identifier">reschedule_until</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.get_thread_pool"> Non-member
+ function <code class="computeroutput"><span class="identifier">get_thread_pool</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.is_worker"> Non-member function
+ <code class="computeroutput"><span class="identifier">is_worker</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.worker_id"> Non-member function
+ <code class="computeroutput"><span class="identifier">worker_id</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"> Class poolsize
</span></dt>
+<dt><span class="section"> Class scanns
</span></dt>
+<dt><span class="section"> Class high_watermark
</span></dt>
+<dt><span class="section"> Class low_watermark
</span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.invalid_poolsize"> Class
+ <code class="computeroutput"><span class="identifier">invalid_poolsize</span></code></a></span></dt>
+<dt><span class="section"> Class invalid_scanns
</span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.invalid_timeduration"> Class
+ <code class="computeroutput"><span class="identifier">invalid_timeduration</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.invalid_watermark"> Class
+ <code class="computeroutput"><span class="identifier">invalid_watermark</span></code></a></span></dt>
+<dt><span class="section"> Class task_rejected
</span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.has_priority"> Meta function
+ <code class="computeroutput"><span class="identifier">has_priority</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.priority_type"> Meta function
+ <code class="computeroutput"><span class="identifier">priority_type</span></code></a></span></dt>
+</dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.pool"></a><a class="link" href="reference.html#boost_threadpool.reference.pool" title="Class template pool"> Class template <code class="computeroutput"><span class="identifier">pool</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.constructor_unbounded_channel_hw">
+ Constructor (unbounded channel)</a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.constructor_unbounded_channel">
+ Constructor (unbounded channel)</a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.constructor_bounded_channel_hw">
+ Constructor (bounded channel)</a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.constructor_bounded_channel">
+ Constructor (bounded channel)</a></span></dt>
+<dt><span class="section"> Destructor</span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.size"> Member function
+ <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.active"> Member function
+ <code class="computeroutput"><span class="identifier">active</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.idle"> Member function
+ <code class="computeroutput"><span class="identifier">idle</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.shutdown"> Member function
+ <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.shutdown_now"> Member
+ function <code class="computeroutput"><span class="identifier">shutdown_now</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.terminated"> Member
+ function <code class="computeroutput"><span class="identifier">terminated</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.terminateing"> Member
+ function <code class="computeroutput"><span class="identifier">terminateing</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.clear"> Member function
+ <code class="computeroutput"><span class="identifier">clear</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.empty"> Member function
+ <code class="computeroutput"><span class="identifier">empty</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.pending"> Member function
+ <code class="computeroutput"><span class="identifier">pending</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.get_upper_bound"> Member
+ function <code class="computeroutput"><span class="identifier">upper_bound</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.set_upper_bound"> Member
+ function <code class="computeroutput"><span class="identifier">upper_bound</span><span class="special">(</span>
+ <span class="identifier">high_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">hwm</span><span class="special">)</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.get_lower_bound"> Member
+ function <code class="computeroutput"><span class="identifier">lower_bound</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.set_lower_bound"> Member
+ function <code class="computeroutput"><span class="identifier">lower_bound</span><span class="special">(</span>
+ <span class="identifier">low_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">lwm</span><span class="special">)</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.submit"> Member function
+ <code class="computeroutput"><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">Act</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">act</span><span class="special">)</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.submit_attr"> Member
+ function <code class="computeroutput"><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">Act</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">act</span><span class="special">,</span> <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">attr</span><span class="special">)</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.pool.get_default_pool">
+ Non-member function <code class="computeroutput"><span class="identifier">get_default_pool</span><span class="special">()</span></code></a></span></dt>
+</dl></div>
+<pre class="programlisting"> <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">pool</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+ <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Channel</span> <span class="special">></span>
+ <span class="keyword">class</span> <span class="identifier">pool</span>
+ <span class="special">:</span> <span class="keyword">private</span> <span class="identifier">noncopyable</span>
+ <span class="special">{</span>
+ <span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">poolsize</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">psize</span><span class="special">,</span>
+ <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">asleep</span> <span class="special">=</span> <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">(</span> <span class="number">10</span><span class="special">),</span>
+ <span class="identifier">scanns</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">scns</span> <span class="special">=</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="number">20</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">poolsize</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">psize</span><span class="special">,</span>
+ <span class="identifier">high_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">hwm</span><span class="special">,</span>
+ <span class="identifier">low_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">lwm</span><span class="special">,</span>
+ <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">asleep</span> <span class="special">=</span> <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span> <span class="number">100</span><span class="special">),</span>
+ <span class="identifier">scanns</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">scns</span> <span class="special">=</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="number">20</span><span class="special">)</span> <span class="special">);</span>
+
+
+ <span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">asleep</span> <span class="special">=</span> <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">(</span> <span class="number">10</span><span class="special">),</span>
+ <span class="identifier">scanns</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">scns</span> <span class="special">=</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="number">20</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">high_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">hwm</span><span class="special">,</span>
+ <span class="identifier">low_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">lwm</span><span class="special">,</span>
+ <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">asleep</span> <span class="special">=</span> <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span> <span class="number">100</span><span class="special">),</span>
+ <span class="identifier">scanns</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">scns</span> <span class="special">=</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="number">20</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="special">~</span><span class="identifier">pool</span><span class="special">();</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">active</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">idle</span><span class="special">();</span>
+
+ <span class="keyword">void</span> <span class="identifier">shutdown</span><span class="special">();</span>
+ <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">callable</span> <span class="special">></span> <span class="identifier">shutdown_now</span><span class="special">();</span>
+
+ <span class="keyword">bool</span> <span class="identifier">terminated</span><span class="special">();</span>
+ <span class="keyword">bool</span> <span class="identifier">terminateing</span><span class="special">();</span>
+ <span class="keyword">void</span> <span class="identifier">clear</span><span class="special">();</span>
+ <span class="keyword">bool</span> <span class="identifier">empty</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">pending</span><span class="special">();</span>
+
+ <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">upper_bound</span><span class="special">();</span>
+ <span class="keyword">void</span> <span class="identifier">upper_bound</span><span class="special">(</span> <span class="identifier">high_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">hwm</span><span class="special">);</span>
+ <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">lower_bound</span><span class="special">();</span>
+ <span class="keyword">void</span> <span class="identifier">lower_bound</span><span class="special">(</span> <span class="identifier">low_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">lwm</span><span class="special">);</span>
+
+ <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Act</span> <span class="special">></span>
+ <span class="identifier">task</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">result_of</span><span class="special"><</span> <span class="identifier">Act</span><span class="special">()</span> <span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> <span class="identifier">submit</span><span class="special">(</span> <span class="identifier">Act</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">act</span><span class="special">);</span>
+
+ <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Act</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr</span> <span class="special">></span>
+ <span class="identifier">task</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">result_of</span><span class="special"><</span> <span class="identifier">Act</span><span class="special">()</span> <span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> <span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">Act</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">act</span><span class="special">,</span>
+ <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">attr</span><span class="special">);</span>
+ <span class="special">};</span>
+
+<span class="identifier">pool</span><span class="special"><</span> <span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">fifo</span> <span class="special">></span> <span class="special">></span> <span class="special">&</span> <span class="identifier">get_default_pool</span><span class="special">();</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.constructor_unbounded_channel_hw"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.constructor_unbounded_channel_hw" title="Constructor (unbounded channel)">
+ Constructor (unbounded channel)</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">asleep</span> <span class="special">=</span> <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">(</span> <span class="number">10</span><span class="special">),</span>
+ <span class="identifier">scanns</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">scns</span> <span class="special">=</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="number">20</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ Operating system provides functionality for processor pining.
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">Channel</span>
+ <span class="special">></span></code> instance. For each processor
+ a worker-thread is created and each worker-thread is pined exactly
+ to one processor.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_scanns</span></code>, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_timeduration</span></code>
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Constructor has to be called if a <a class="link" href="channel.html#boost_threadpool.channel.unbounded_channel"><span class="emphasis"><em>unbounded
+ channel</em></span></a> is used.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.constructor_unbounded_channel"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.constructor_unbounded_channel" title="Constructor (unbounded channel)">
+ Constructor (unbounded channel)</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">poolsize</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">psize</span><span class="special">,</span>
+ <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">asleep</span> <span class="special">=</span> <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">(</span> <span class="number">10</span><span class="special">),</span>
+ <span class="identifier">scanns</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">scns</span> <span class="special">=</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="number">20</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">Channel</span>
+ <span class="special">></span></code> instance. Pool contains
+ psize worker-threads.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_scanns</span></code>, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_timeduration</span></code>
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Constructor has to be called if a <a class="link" href="channel.html#boost_threadpool.channel.unbounded_channel"><span class="emphasis"><em>unbounded
+ channel</em></span></a> is used.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.constructor_bounded_channel_hw"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.constructor_bounded_channel_hw" title="Constructor (bounded channel)">
+ Constructor (bounded channel)</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">high_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">hwm</span><span class="special">,</span>
+ <span class="identifier">low_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">lwm</span><span class="special">,</span>
+ <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">asleep</span> <span class="special">=</span> <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span> <span class="number">100</span><span class="special">),</span>
+ <span class="identifier">scanns</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">scns</span> <span class="special">=</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="number">20</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ Operating system provides functionality for processor pining.
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">Channel</span>
+ <span class="special">></span></code> instance. For each processor
+ a worker-thread is created and each worker-thread is pined exactly
+ to one processor.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_scanns</span></code>, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_timeduration</span></code>,
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_watermark</span></code>
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Constructor has to be called if a <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a> is used.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.constructor_bounded_channel"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.constructor_bounded_channel" title="Constructor (bounded channel)">
+ Constructor (bounded channel)</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">poolsize</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">psize</span><span class="special">,</span>
+ <span class="identifier">high_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">hwm</span><span class="special">,</span>
+ <span class="identifier">low_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">lwm</span><span class="special">,</span>
+ <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">asleep</span> <span class="special">=</span> <span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span> <span class="number">100</span><span class="special">),</span>
+ <span class="identifier">scanns</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">scns</span> <span class="special">=</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="number">20</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">Channel</span>
+ <span class="special">></span></code> instance. Pool contains
+ psize worker-threads.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_scanns</span></code>, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_timeduration</span></code>,
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_watermark</span></code>
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Constructor has to be called if a <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a> is used.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.destructor"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.destructor" title="Destructor"> Destructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="special">~</span><span class="identifier">pool</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Calls <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">Channel</span> <span class="special">>::</span><span class="identifier">shutdown</span><span class="special">()</span></code>
+ if not yet called.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.size"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.size" title="Member function size()"> Member function
+ <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns how many worker threads are running in the pool.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.active"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.active" title="Member function active()"> Member function
+ <code class="computeroutput"><span class="identifier">active</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">active</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns how many worker threads are active (executing an action).
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.idle"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.idle" title="Member function idle()"> Member function
+ <code class="computeroutput"><span class="identifier">idle</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">idle</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns how many worker threads are idle (not executing an action).
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ The value is the difference of <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">active</span><span class="special">()</span></code>
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.shutdown"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.shutdown" title="Member function shutdown()"> Member function
+ <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">shutdown</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Changes the pool state to <span class="emphasis"><em>terminating</em></span>, deactivates
+ the channel and joins all worker threads. The status of the pool is
+ assigned to <span class="emphasis"><em>terminated</em></span> at the end.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ All pending actions are processed.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.shutdown_now"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.shutdown_now" title="Member function shutdown_now()"> Member
+ function <code class="computeroutput"><span class="identifier">shutdown_now</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span> <span class="identifier">callable</span> <span class="special">></span> <span class="identifier">shutdown_now</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Changes the pool state to <span class="emphasis"><em>terminating</em></span>, deactivates
+ the channel, send interruption request to all worker threads and joins
+ them. The status of the pool is assigned to <span class="emphasis"><em>terminated</em></span>
+ at the end.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Pending actions are not processed but returned.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.terminated"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.terminated" title="Member function terminated()"> Member
+ function <code class="computeroutput"><span class="identifier">terminated</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">terminated</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Queries if the pool is in the terminated state (pool is shutdown).
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.terminateing"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.terminateing" title="Member function terminateing()"> Member
+ function <code class="computeroutput"><span class="identifier">terminateing</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">terminateing</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Queries if the pool is in the terminating state (tries to shutdown
+ the pool).
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.clear"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.clear" title="Member function clear()"> Member function
+ <code class="computeroutput"><span class="identifier">clear</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">clear</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Removes all pending actions from the <a class="link" href="channel.html" title="Channel"><span class="emphasis"><em>channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.empty"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.empty" title="Member function empty()"> Member function
+ <code class="computeroutput"><span class="identifier">empty</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">empty</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Queries if the <a class="link" href="channel.html" title="Channel"><span class="emphasis"><em>channel</em></span></a>
+ is empty.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.pending"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.pending" title="Member function pending()"> Member function
+ <code class="computeroutput"><span class="identifier">pending</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">pending</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Queries how many actions are pending in the <a class="link" href="channel.html" title="Channel"><span class="emphasis"><em>channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.get_upper_bound"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.get_upper_bound" title="Member function upper_bound()"> Member
+ function <code class="computeroutput"><span class="identifier">upper_bound</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">upper_bound</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ Channel is of type <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns the upper bound of the <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Can only be used if a <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a> is used.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.set_upper_bound"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.set_upper_bound" title="Member function upper_bound( high_watermark const& hwm)"> Member
+ function <code class="computeroutput"><span class="identifier">upper_bound</span><span class="special">(</span>
+ <span class="identifier">high_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">hwm</span><span class="special">)</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">upper_bound</span><span class="special">(</span> <span class="identifier">high_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">hwm</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ Channel is of type <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Sets the upper bound of the <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Postconditions:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">upper_bound</span><span class="special">()</span>
+ <span class="special">==</span> <span class="identifier">hwm</span></code>.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_watermark</span></code>
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Can only be used if a <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a> is used.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.get_lower_bound"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.get_lower_bound" title="Member function lower_bound()"> Member
+ function <code class="computeroutput"><span class="identifier">lower_bound</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">lower_bound</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ Channel is of type <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns the lower bound of the <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Can only be used if a <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a> is used.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.set_lower_bound"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.set_lower_bound" title="Member function lower_bound( low_watermark const& lwm)"> Member
+ function <code class="computeroutput"><span class="identifier">lower_bound</span><span class="special">(</span>
+ <span class="identifier">low_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">lwm</span><span class="special">)</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">lower_bound</span><span class="special">(</span> <span class="identifier">low_watermark</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">lwm</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ Channel is of type <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Sets the lower bound of the <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a>.
+ </p></dd>
+<dt><span class="term">Postconditions:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="keyword">this</span><span class="special">-></span><span class="identifier">lower_bound</span><span class="special">()</span>
+ <span class="special">==</span> <span class="identifier">lwm</span></code>.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_watermark</span></code>
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ Can only be used if a <a class="link" href="channel.html#boost_threadpool.channel.bounded_channel"><span class="emphasis"><em>bounded
+ channel</em></span></a> is used.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.submit"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.submit" title="Member function submit( Act const& act)"> Member function
+ <code class="computeroutput"><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">Act</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">act</span><span class="special">)</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Act</span> <span class="special">></span>
+<span class="identifier">task</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">result_of</span><span class="special"><</span> <span class="identifier">Act</span><span class="special">()</span> <span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> <span class="identifier">submit</span><span class="special">(</span> <span class="identifier">Act</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">act</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ has_priority< pool >::value == false && ! ( pool.terminating()
+ || pool.terminated() )
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Submits an action to the pool and returns a <a class="link" href="task.html" title="Task"><span class="emphasis"><em>task</em></span></a>
+ object.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task_rejected</span></code>
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.submit_attr"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.submit_attr" title="Member function submit( Act const& act, Attr const& attr)"> Member
+ function <code class="computeroutput"><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">Act</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">act</span><span class="special">,</span> <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">attr</span><span class="special">)</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Act</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr</span> <span class="special">></span>
+<span class="identifier">task</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">result_of</span><span class="special"><</span> <span class="identifier">Act</span><span class="special">()</span> <span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> <span class="identifier">submit</span><span class="special">(</span> <span class="identifier">Act</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">act</span><span class="special">,</span> <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">attr</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ has_priority< pool >::value == true && ! ( pool.terminating()
+ || pool.terminated() )
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Submits an action to the pool and returns a <a class="link" href="task.html" title="Task"><span class="emphasis"><em>task</em></span></a>
+ object. <span class="underline">_Action</span>_ is scheduled
+ by the attribute.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task_rejected</span></code>
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.pool.get_default_pool"></a><a class="link" href="reference.html#boost_threadpool.reference.pool.get_default_pool" title="Non-member function get_default_pool()">
+ Non-member function <code class="computeroutput"><span class="identifier">get_default_pool</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">pool</span><span class="special"><</span> <span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">fifo</span> <span class="special">></span> <span class="special">></span> <span class="special">&</span> <span class="identifier">get_default_pool</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Get access to default thread pool (static).
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.task"></a><a class="link" href="reference.html#boost_threadpool.reference.task" title="Class template task"> Class template <code class="computeroutput"><span class="identifier">task</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"> Constructor</span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.task.interrupt"> Member
+ function <code class="computeroutput"><span class="identifier">interrupt</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.task.interrupt_and_wait">
+ Member function <code class="computeroutput"><span class="identifier">interrupt_and_wait</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.task.result"> Member function
+ <code class="computeroutput"><span class="identifier">result</span><span class="special">()</span></code></a></span></dt>
+</dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">task</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">R</span> <span class="special">></span>
+<span class="keyword">class</span> <span class="identifier">task</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Pool</span> <span class="special">></span>
+ <span class="identifier">task</span><span class="special">(</span>
+ <span class="identifier">Pool</span> <span class="special">*</span> <span class="identifier">pool</span><span class="special">,</span>
+ <span class="identifier">shared_future</span><span class="special"><</span> <span class="identifier">R</span> <span class="special">></span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">fut</span><span class="special">,</span>
+ <span class="identifier">detail</span><span class="special">::</span><span class="identifier">interrupter</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">intr</span><span class="special">);</span>
+
+ <span class="keyword">void</span> <span class="identifier">interrupt</span><span class="special">();</span>
+ <span class="keyword">void</span> <span class="identifier">interrupt_and_wait</span><span class="special">();</span>
+ <span class="keyword">void</span> <span class="identifier">interrupt_and_wait</span><span class="special">(</span> <span class="identifier">system_time</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">abs_time</span><span class="special">);</span>
+ <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Duration</span> <span class="special">></span>
+ <span class="keyword">void</span> <span class="identifier">interrupt_and_wait</span><span class="special">(</span> <span class="identifier">Duration</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rel_time</span><span class="special">);</span>
+ <span class="keyword">bool</span> <span class="identifier">interrupt_requested</span><span class="special">();</span>
+
+ <span class="identifier">shared_future</span><span class="special"><</span> <span class="identifier">R</span> <span class="special">></span> <span class="identifier">result</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.task.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.task.constructor" title="Constructor"> Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Pool</span> <span class="special">></span>
+<span class="identifier">task</span><span class="special">(</span>
+ <span class="identifier">Pool</span> <span class="special">*</span> <span class="identifier">pool</span><span class="special">,</span>
+ <span class="identifier">shared_future</span><span class="special"><</span> <span class="identifier">R</span> <span class="special">></span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">fut</span><span class="special">,</span>
+ <span class="identifier">detail</span><span class="special">::</span><span class="identifier">interrupter</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">intr</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="identifier">R</span>
+ <span class="special">></span></code> instance.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+<dt><span class="term">Notes:</span></dt>
+<dd><p>
+ task objects should only be constructed by the pool.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.task.interrupt"></a><a class="link" href="reference.html#boost_threadpool.reference.task.interrupt" title="Member function interrupt()"> Member
+ function <code class="computeroutput"><span class="identifier">interrupt</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">interrupt</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Associated action will be interrupted the next time it enters a <a class="link" href="task.html#boost_threadpool.task.interruption"><span class="emphasis"><em>interruption
+ point</em></span></a> if interruption is not disabled. The function
+ returns immediatly.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.task.interrupt_and_wait"></a><a class="link" href="reference.html#boost_threadpool.reference.task.interrupt_and_wait" title="Member function interrupt_and_wait()">
+ Member function <code class="computeroutput"><span class="identifier">interrupt_and_wait</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">interrupt_and_wait</span><span class="special">();</span>
+
+<span class="keyword">void</span> <span class="identifier">interrupt_and_wait</span><span class="special">(</span> <span class="identifier">system_time</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">abs_time</span><span class="special">);</span>
+
+<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">DurationTime</span> <span class="special">></span>
+<span class="keyword">void</span> <span class="identifier">interrupt_and_wait</span><span class="special">(</span> <span class="identifier">DurationTime</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rel_time</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Associated action will be interrupted the next time it enters one
+ <a class="link" href="task.html#boost_threadpool.task.interruption"><span class="emphasis"><em>interruption
+ point</em></span></a> if interruption is not disabled. The function
+ waits until the action has terminated or the specified duration td
+ has elapsed.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.task.result"></a><a class="link" href="reference.html#boost_threadpool.reference.task.result" title="Member function result()"> Member function
+ <code class="computeroutput"><span class="identifier">result</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">shared_future</span><span class="special"><</span> <span class="identifier">R</span> <span class="special">></span> <span class="identifier">result</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns fulfilled value or throws fulfilled exception via a shared_future.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">future</span><span class="special">::</span><span class="identifier">broken_promise</span></code>
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.reschedule_until"></a><a class="link" href="reference.html#boost_threadpool.reference.reschedule_until" title="Non-member function reschedule_until()"> Non-member
+ function <code class="computeroutput"><span class="identifier">reschedule_until</span><span class="special">()</span></code></a>
+</h3></div></div></div>
+<pre class="programlisting"> <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">pool</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Pred</span> <span class="special">></span>
+<span class="keyword">void</span> <span class="identifier">reschedule_until</span><span class="special">(</span> <span class="identifier">Pred</span> <span class="keyword">const</span><span class="special">&);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd>
+<p>
+ Reschedules current task until passed callable predicate becomes ready.
+ </p>
+<p>
+ [Throws:
+ </p>
+<p>
+ Nothing.
+ </p>
+</dd>
+<dt><span class="term">Note:</span></dt>
+<dd><p>
+ This function resides in namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span></code>.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.get_thread_pool"></a><a class="link" href="reference.html#boost_threadpool.reference.get_thread_pool" title="Non-member function get_thread_pool()"> Non-member
+ function <code class="computeroutput"><span class="identifier">get_thread_pool</span><span class="special">()</span></code></a>
+</h3></div></div></div>
+<pre class="programlisting"> <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">pool</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Pool</span> <span class="special">></span>
+<span class="identifier">Pool</span> <span class="special">&</span> <span class="identifier">get_thread_pool</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd>
+<p>
+ Returns reference to the thread pool where the current worker thread
+ is running.
+ </p>
+<p>
+ [Throws:
+ </p>
+<p>
+ Nothing.
+ </p>
+</dd>
+<dt><span class="term">Note:</span></dt>
+<dd><p>
+ This function resides in namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span></code>.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.is_worker"></a><a class="link" href="reference.html#boost_threadpool.reference.is_worker" title="Non-member function is_worker()"> Non-member function
+ <code class="computeroutput"><span class="identifier">is_worker</span><span class="special">()</span></code></a>
+</h3></div></div></div>
+<pre class="programlisting"> <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">pool</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">bool</span> <span class="identifier">is_worker</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd>
+<p>
+ Returns true if the current thread is a worker-thread form a pool.
+ </p>
+<p>
+ [Throws:
+ </p>
+<p>
+ Nothing.
+ </p>
+</dd>
+<dt><span class="term">Note:</span></dt>
+<dd><p>
+ This function resides in namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span></code>.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.worker_id"></a><a class="link" href="reference.html#boost_threadpool.reference.worker_id" title="Non-member function worker_id()"> Non-member function
+ <code class="computeroutput"><span class="identifier">worker_id</span><span class="special">()</span></code></a>
+</h3></div></div></div>
+<pre class="programlisting"> <span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">pool</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="identifier">thread</span><span class="special">::</span><span class="identifier">id</span> <span class="identifier">worker_id</span><span class="special">();</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd>
+<p>
+ Returns returns the thread-id of the worker-thread.
+ </p>
+<p>
+ [Throws:
+ </p>
+<p>
+ Nothing.
+ </p>
+</dd>
+<dt><span class="term">Note:</span></dt>
+<dd><p>
+ This function resides in namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span></code>.
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.poolsize"></a><a class="link" href="reference.html#boost_threadpool.reference.poolsize" title="Class poolsize"> Class <code class="computeroutput"><span class="identifier">poolsize</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"> Constructor</span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.poolsize.operator"> Member
+ function <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()</span></code></a></span></dt>
+</dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">poolsize</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">poolsize</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">explicit</span> <span class="identifier">poolsize</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">value</span><span class="special">);</span>
+
+ <span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.poolsize.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.poolsize.constructor" title="Constructor"> Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">poolsize</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">value</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ value > 0
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Postconditions:</span></dt>
+<dd><p>
+ operator std::size_t () > 0
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_poolsize</span></code>
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.poolsize.operator"></a><a class="link" href="reference.html#boost_threadpool.reference.poolsize.operator" title="Member function operator std::size_t()"> Member
+ function <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns pool size.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.scanns"></a><a class="link" href="reference.html#boost_threadpool.reference.scanns" title="Class scanns"> Class <code class="computeroutput"><span class="identifier">scanns</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"> Constructor</span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.scanns.operator"> Member
+ function <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()</span></code></a></span></dt>
+</dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">scanns</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">scanns</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">explicit</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">value</span><span class="special">);</span>
+
+ <span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.scanns.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.scanns.constructor" title="Constructor"> Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">scanns</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">value</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Preconditions:</span></dt>
+<dd><p>
+ value >= 0
+ </p></dd>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">scanns</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Postconditions:</span></dt>
+<dd><p>
+ operator std::size_t () >= 0
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_scanns</span></code>
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.scanns.operator"></a><a class="link" href="reference.html#boost_threadpool.reference.scanns.operator" title="Member function operator std::size_t()"> Member
+ function <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns scanns size.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.high_watermark"></a><a class="link" href="reference.html#boost_threadpool.reference.high_watermark" title="Class high_watermark"> Class <code class="computeroutput"><span class="identifier">high_watermark</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.high_watermark.constructor">
+ Constructor</a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.high_watermark.operator">
+ Member function <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()</span></code></a></span></dt>
+</dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">watermark</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">high_watermark</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">explicit</span> <span class="identifier">high_watermark</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">value</span><span class="special">);</span>
+
+ <span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.high_watermark.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.high_watermark.constructor" title="Constructor">
+ Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">high_watermark</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">value</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">high_watermark</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_watermark</span></code>
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.high_watermark.operator"></a><a class="link" href="reference.html#boost_threadpool.reference.high_watermark.operator" title="Member function operator std::size_t()">
+ Member function <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns high watermark.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.low_watermark"></a><a class="link" href="reference.html#boost_threadpool.reference.low_watermark" title="Class low_watermark"> Class <code class="computeroutput"><span class="identifier">low_watermark</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.low_watermark.constructor">
+ Constructor</a></span></dt>
+<dt><span class="section"><a href="reference.html#boost_threadpool.reference.low_watermark.operator">
+ Member function <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()</span></code></a></span></dt>
+</dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">watermark</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">low_watermark</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">explicit</span> <span class="identifier">low_watermark</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">value</span><span class="special">);</span>
+
+ <span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.low_watermark.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.low_watermark.constructor" title="Constructor">
+ Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">explicit</span> <span class="identifier">low_watermark</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">value</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">low_watermark</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_watermark</span></code>
+ </p></dd>
+</dl>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.low_watermark.operator"></a><a class="link" href="reference.html#boost_threadpool.reference.low_watermark.operator" title="Member function operator std::size_t()">
+ Member function <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">()</span></code></a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="keyword">operator</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Returns low watermark.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.invalid_poolsize"></a><a class="link" href="reference.html#boost_threadpool.reference.invalid_poolsize" title="Class invalid_poolsize"> Class
+ <code class="computeroutput"><span class="identifier">invalid_poolsize</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="reference.html#boost_threadpool.reference.invalid_poolsize.constructor">
+ Constructor</a></span></dt></dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">exceptions</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">invalid_poolsize</span>
+<span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">invalid_poolsize</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.invalid_poolsize.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.invalid_poolsize.constructor" title="Constructor">
+ Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">invalid_poolsize</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_poolsize</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.invalid_scanns"></a><a class="link" href="reference.html#boost_threadpool.reference.invalid_scanns" title="Class invalid_scanns"> Class <code class="computeroutput"><span class="identifier">invalid_scanns</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="reference.html#boost_threadpool.reference.invalid_scanns.constructor">
+ Constructor</a></span></dt></dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">exceptions</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">invalid_scanns</span>
+<span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">invalid_scanns</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.invalid_scanns.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.invalid_scanns.constructor" title="Constructor">
+ Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">invalid_scanns</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_scanns</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.invalid_timeduration"></a><a class="link" href="reference.html#boost_threadpool.reference.invalid_timeduration" title="Class invalid_timeduration"> Class
+ <code class="computeroutput"><span class="identifier">invalid_timeduration</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="reference.html#boost_threadpool.reference.invalid_timeduration.constructor">
+ Constructor</a></span></dt></dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">exceptions</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">invalid_timeduration</span>
+<span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">invalid_timeduration</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.invalid_timeduration.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.invalid_timeduration.constructor" title="Constructor">
+ Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">invalid_timeduration</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_timeduration</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.invalid_watermark"></a><a class="link" href="reference.html#boost_threadpool.reference.invalid_watermark" title="Class invalid_watermark"> Class
+ <code class="computeroutput"><span class="identifier">invalid_watermark</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="reference.html#boost_threadpool.reference.invalid_watermark.constructor">
+ Constructor</a></span></dt></dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">exceptions</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">invalid_watermark</span>
+<span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">invalid_watermark</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.invalid_watermark.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.invalid_watermark.constructor" title="Constructor">
+ Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">invalid_watermark</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">invalid_watermark</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.task_rejected"></a><a class="link" href="reference.html#boost_threadpool.reference.task_rejected" title="Class task_rejected"> Class <code class="computeroutput"><span class="identifier">task_rejected</span></code></a>
+</h3></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="reference.html#boost_threadpool.reference.task_rejected.constructor">
+ Constructor</a></span></dt></dl></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">exceptions</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">class</span> <span class="identifier">task_rejected</span>
+<span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">task_rejected</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_threadpool.reference.task_rejected.constructor"></a><a class="link" href="reference.html#boost_threadpool.reference.task_rejected.constructor" title="Constructor">
+ Constructor</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="identifier">task_rejected</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">msg</span><span class="special">);</span>
+</pre>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Effects:</span></dt>
+<dd><p>
+ Constructs a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task_rejected</span></code>
+ instance.
+ </p></dd>
+<dt><span class="term">Throws:</span></dt>
+<dd><p>
+ Nothing
+ </p></dd>
+</dl>
+</div>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.has_priority"></a><a class="link" href="reference.html#boost_threadpool.reference.has_priority" title="Meta function has_priority"> Meta function
+ <code class="computeroutput"><span class="identifier">has_priority</span></code></a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">info</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Pool</span> <span class="special">></span>
+<span class="keyword">struct</span> <span class="identifier">has_priority</span>
+<span class="special">:</span>
+<span class="keyword">public</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">bool_</span><span class="special"><</span>
+ <span class="identifier">is_same</span><span class="special"><</span>
+ <span class="identifier">detail</span><span class="special">::</span><span class="identifier">has_priority</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">Pool</span><span class="special">::</span><span class="identifier">scheduler_type</span><span class="special">::</span><span class="identifier">priority_tag_type</span>
+ <span class="special">>::</span><span class="identifier">value</span>
+<span class="special">></span>
+<span class="special">{};</span>
+</pre>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_threadpool.reference.priority_type"></a><a class="link" href="reference.html#boost_threadpool.reference.priority_type" title="Meta function priority_type"> Meta function
+ <code class="computeroutput"><span class="identifier">priority_type</span></code></a>
+</h3></div></div></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">info</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Pool</span> <span class="special">></span>
+<span class="keyword">struct</span> <span class="identifier">priority_type</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Pool</span><span class="special">::</span><span class="identifier">scheduler_type</span><span class="special">::</span><span class="identifier">attribute_type</span> <span class="identifier">type</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Oliver Kowalke<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="acknowledgement.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a>
+</div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/html/boost_threadpool/scheduling.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/boost_threadpool/scheduling.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,132 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Scheduling</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="prev" href="channel.html" title="Channel">
+<link rel="next" href="forkjoin.html" title="Fork/Join">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="channel.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="forkjoin.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.scheduling"></a><a class="link" href="scheduling.html" title="Scheduling"> Scheduling</a>
+</h2></div></div></div>
+<p>
+ The scheduling policy determines how actions are scheduled inside the <a class="link" href="channel.html" title="Channel"><span class="emphasis"><em>channel</em></span></a>.
+ </p>
+<a name="boost_threadpool.scheduling.fifo"></a><h4>
+<a name="id372440"></a>
+ <a class="link" href="scheduling.html#boost_threadpool.scheduling.fifo">fifo</a>
+ </h4>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">fifo</span>
+</pre>
+<p>
+ First inserted pending action get taken first.
+ </p>
+<a name="boost_threadpool.scheduling.lifo"></a><h4>
+<a name="id372473"></a>
+ <a class="link" href="scheduling.html#boost_threadpool.scheduling.lifo">lifo</a>
+ </h4>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">lifo</span>
+</pre>
+<p>
+ Last inserted pending action get taken first.
+ </p>
+<a name="boost_threadpool.scheduling.priority"></a><h4>
+<a name="id372506"></a>
+ <a class="link" href="scheduling.html#boost_threadpool.scheduling.priority">priority</a>
+ </h4>
+<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Ord</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special"><</span> <span class="identifier">Attr</span> <span class="special">></span> <span class="special">></span> <span class="keyword">struct</span> <span class="identifier">priority</span>
+</pre>
+<p>
+ Each pending task is associated with a priority attribute which is used for
+ ordering actions.
+ </p>
+<a name="boost_threadpool.scheduling.smart"></a><h4>
+<a name="id372612"></a>
+ <a class="link" href="scheduling.html#boost_threadpool.scheduling.smart">smart</a>
+ </h4>
+<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Ord</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Enq</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Deq</span> <span class="special">></span> <span class="keyword">struct</span> <span class="identifier">smart</span>
+</pre>
+<p>
+ Each pending actions is associated with an attribute. The scheduler gets an
+ put- and take-policy as template arguments. The corresponding policy get applied
+ for each insertion and removal.
+ </p>
+<p>
+ <span class="bold"><strong>Boost.Threadpool</strong></span> provides <span class="emphasis"><em>boost::tp::replace_oldest</em></span>
+ as put policy and <span class="emphasis"><em>boost::tp::take_oldest</em></span> as take policy.
+ Both policies allow the replacement of old actions in the scheduler by new
+ ones.
+ </p>
+<pre class="programlisting"><span class="comment">// creates a pool with unbounded channel
+</span><span class="comment">// tasks are processed depending on the associated attributed
+</span><span class="comment">// oldest tasks with the same attributed pending in the channel
+</span><span class="comment">// will be replaced by the new task
+</span><span class="comment">// this example would execute add( 1, 2) and add( 5, 6)
+</span><span class="comment">// add( 2, 3) is removed (if pending when add( 5, 6) is submitted)
+</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">smart</span><span class="special"><</span>
+ <span class="keyword">int</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">>,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">replace_oldest</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">take_oldest</span>
+ <span class="special">></span>
+ <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">1</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">add_fn</span><span class="special">,</span>
+ <span class="number">1</span><span class="special">,</span>
+ <span class="number">2</span><span class="special">),</span>
+ <span class="number">0</span><span class="special">);</span>
+
+<span class="comment">// replaced by later task with same attribute
+</span><span class="comment">// if still pending in pool
+</span><span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">add_fn</span><span class="special">,</span>
+ <span class="number">3</span><span class="special">,</span>
+ <span class="number">4</span><span class="special">),</span>
+ <span class="number">1</span><span class="special">);</span>
+
+<span class="comment">// will replace previous pending action
+</span><span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">add_fn</span><span class="special">,</span>
+ <span class="number">5</span><span class="special">,</span>
+ <span class="number">6</span><span class="special">),</span>
+ <span class="number">1</span><span class="special">);</span>
+</pre>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Oliver Kowalke<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="channel.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="forkjoin.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/html/boost_threadpool/task.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/boost_threadpool/task.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,185 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Task</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="prev" href="pool.html" title="Pool">
+<link rel="next" href="this_task.html" title="Namespace this_task">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="pool.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="this_task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.task"></a><a class="link" href="task.html" title="Task"> Task</a>
+</h2></div></div></div>
+<p>
+ For each submitted action a new task object will be created and returned by
+ the pool. The <a class="link" href="task.html" title="Task"><span class="emphasis"><em>task</em></span></a>
+ object acts as a proxy for a result that is initially not known and gets evaluated
+ later by a worker thread. It transports the result (value or exception) of
+ the action back to the caller.
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">10</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="comment">// task calculates fibonacci(10)
+</span><span class="comment">// scheduled in unbounded channel with FIFO ordering
+</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t</span><span class="special">(</span>
+<span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">fibonacci_fn</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// 55
+</span></pre>
+<a name="boost_threadpool.task.interruption"></a><h4>
+<a name="id370144"></a>
+ <a class="link" href="task.html#boost_threadpool.task.interruption">Interruption</a>
+ </h4>
+<p>
+ The returned <a class="link" href="task.html" title="Task"><span class="emphasis"><em>task</em></span></a>
+ object provides the possiblity to interrupt an action if it is cooperative.
+ An action is known as cooperative if it includes interruption points in its
+ code:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">join</span><span class="special">()</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">timed_join</span><span class="special">()</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable</span><span class="special">::</span><span class="identifier">wait</span><span class="special">()</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable</span><span class="special">::</span><span class="identifier">timed_wait</span><span class="special">()</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable_any</span><span class="special">::</span><span class="identifier">wait</span><span class="special">()</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable_any</span><span class="special">::</span><span class="identifier">timed_wait</span><span class="special">()</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">sleep</span><span class="special">()</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep</span><span class="special">()</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">()</span></code></li>
+</ul></div>
+<div class="important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../doc/html/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Interruption must not be disabled for the worker thread (class <span class="emphasis"><em>boost::this_thread::disable_interruption</em></span>).
+ </p></td></tr>
+</table></div>
+<p>
+ The action will be interrupted even if it is pending (interruption is remembered).
+ A <span class="emphasis"><em>boost::thread_interrupted</em></span> exception will be thrown by
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="identifier">T</span> <span class="special">>::</span><span class="identifier">get</span><span class="special">()</span></code> if
+ the action was interrupted.
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">10</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="comment">// submit a long running task
+</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">long_running_fn</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+<span class="comment">// interrupt task
+</span><span class="identifier">t</span><span class="special">.</span><span class="identifier">interrupt</span><span class="special">();</span>
+
+<span class="comment">// throws boost::thread_interrupted exception
+</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+</pre>
+<p>
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">10</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="comment">// submit a long running task
+</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">long_running_fn</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+<span class="comment">// interrupt task and wait for its termination
+</span><span class="identifier">t</span><span class="special">.</span><span class="identifier">interrupt_and_wait</span><span class="special">();</span>
+
+<span class="comment">// throws boost::thread_interrupted exception
+</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+</pre>
+<a name="boost_threadpool.task.exceptions_in_tasks"></a><h4>
+<a name="id371198"></a>
+ <a class="link" href="task.html#boost_threadpool.task.exceptions_in_tasks">Exceptions in tasks</a>
+ </h4>
+<p>
+ Exceptions thrown inside an action are transported by the associated task object.
+ Exceptions rethrown by type:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_alloc</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_cast</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_exception</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_typeid</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">domain_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">failure</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">length_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">logic_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">out_of_range</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">range_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">underflow_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">broken_promise</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">future_already_set</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">future_cancel</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">invalid_thread_argument</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">lock_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_exception</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_interrupted</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_permission_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread_resource_error</span></code></li>
+<li><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">unsupported_thread_option</span></code></li>
+</ul></div>
+<p>
+ Exceptions derived from <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span></code>
+ will be rethrown as <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code> in all other cases a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_exception</span></code>
+ is thrown.
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">pool</span><span class="special"><</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">></span>
+<span class="special">></span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">10</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="comment">// task will throw an exception derived from std::exception
+</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">task</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="identifier">t</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">submit</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">bind</span><span class="special">(</span>
+ <span class="identifier">throwing_fn</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">result</span><span class="special">().</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// will rethrow an std::runtime_error
+</span></pre>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Oliver Kowalke<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="pool.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="this_task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/html/boost_threadpool/this_task.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/boost_threadpool/this_task.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,52 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Namespace this_task</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="prev" href="task.html" title="Task">
+<link rel="next" href="channel.html" title="Channel">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="task.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="channel.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.this_task"></a><a class="link" href="this_task.html" title="Namespace this_task"> Namespace this_task</a>
+</h2></div></div></div>
+<p>
+ In the function <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">reschedule_until</span><span class="special">(</span>
+ <span class="identifier">Pred</span> <span class="keyword">const</span><span class="special">&)</span></code> allows to synchronize the task with other
+ asynchronous events without blocking the worker threads (bool Pred::operator()()
+ must not block) The current task will be rescheduled until the passed predicate
+ becomes true. The pool can be accessed via <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_thread_pool</span><span class="special"><</span> <span class="identifier">Pool</span> <span class="special">>()</span></code> if the calling code is executed by a
+ worker thread. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">s_worker</span><span class="special">()</span></code>
+ evaluates true if the current thread is worker thread and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">worker_id</span><span class="special">()</span></code> returns the thread id.
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Oliver Kowalke<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="task.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="channel.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/html/index.html
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/html/index.html 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,129 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Chapter 1. Boost.Threadpool</title>
+<link rel="stylesheet" href="boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
+<link rel="start" href="index.html" title="Chapter 1. Boost.Threadpool">
+<link rel="next" href="boost_threadpool/pool.html" title="Pool">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav"><a accesskey="n" href="boost_threadpool/pool.html"><img src="../../doc/html/images/next.png" alt="Next"></a></div>
+<div class="chapter" lang="en">
+<div class="titlepage"><div>
+<div><h2 class="title">
+<a name="boost_threadpool"></a>Chapter 1. Boost.Threadpool</h2></div>
+<div><div class="author"><h3 class="author">
+<span class="firstname">Oliver</span> <span class="surname">Kowalke</span>
+</h3></div></div>
+<div><p class="copyright">Copyright © 2008 Oliver Kowalke</p></div>
+<div><div class="legalnotice">
+<a name="id358702"></a><p>
+ 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)
+ </p>
+</div></div>
+</div></div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="section">Introduction</span></dt>
+<dt><span class="section"> Pool</span></dt>
+<dt><span class="section"> Task</span></dt>
+<dt><span class="section"> Namespace this_task</span></dt>
+<dt><span class="section"> Channel</span></dt>
+<dt><span class="section"> Scheduling</span></dt>
+<dt><span class="section"> Fork/Join</span></dt>
+<dt><span class="section"> Acknowledgements</span></dt>
+<dt><span class="section"> Reference</span></dt>
+<dd><dl>
+<dt><span class="section"> Class template pool
</span></dt>
+<dt><span class="section"> Class template task
</span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.reschedule_until"> Non-member
+ function <code class="computeroutput"><span class="identifier">reschedule_until</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.get_thread_pool"> Non-member
+ function <code class="computeroutput"><span class="identifier">get_thread_pool</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.is_worker"> Non-member function
+ <code class="computeroutput"><span class="identifier">is_worker</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.worker_id"> Non-member function
+ <code class="computeroutput"><span class="identifier">worker_id</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"> Class poolsize
</span></dt>
+<dt><span class="section"> Class scanns
</span></dt>
+<dt><span class="section"> Class high_watermark
</span></dt>
+<dt><span class="section"> Class low_watermark
</span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.invalid_poolsize"> Class
+ <code class="computeroutput"><span class="identifier">invalid_poolsize</span></code></a></span></dt>
+<dt><span class="section"> Class invalid_scanns
</span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.invalid_timeduration"> Class
+ <code class="computeroutput"><span class="identifier">invalid_timeduration</span></code></a></span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.invalid_watermark"> Class
+ <code class="computeroutput"><span class="identifier">invalid_watermark</span></code></a></span></dt>
+<dt><span class="section"> Class task_rejected
</span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.has_priority"> Meta function
+ <code class="computeroutput"><span class="identifier">has_priority</span></code></a></span></dt>
+<dt><span class="section"><a href="boost_threadpool/reference.html#boost_threadpool.reference.priority_type"> Meta function
+ <code class="computeroutput"><span class="identifier">priority_type</span></code></a></span></dt>
+</dl></dd>
+</dl>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_threadpool.introduction"></a><a class="link" href="index.html#boost_threadpool.introduction" title="Introduction">Introduction</a>
+</h2></div></div></div>
+<p>
+ <span class="bold"><strong>Boost.Threadpool</strong></span> is designed for effectively
+ utilize the available hardware and provide a way for efficient asynchronous
+ processing of independent time consuming operations (actions) in the same process.
+ A thread pool contains a number of worker threads to perform actions in parallel,
+ which are usually managed by a scheduler. If a worker thread completes its
+ action, it will take the next action from the scheduler until all actions have
+ been completed. The worker thread then sleeps until there are new actions available.
+ Using a pool of worker threads over creating a new thread for each action may
+ result in better performance and better system stability because the overhead
+ for thread creation and destruction is negated.
+ </p>
+<p>
+ <span class="bold"><strong>Boost.Threadpool</strong></span> uses a <a class="link" href="boost_threadpool/pool.html#boost_threadpool.pool.work_stealing"><span class="emphasis"><em>work
+ stealing</em></span></a> algorithm and supports <a class="link" href="boost_threadpool/forkjoin.html" title="Fork/Join"><span class="emphasis"><em>fork/join</em></span></a>
+ parallelism (recursively splitting of actions into sub-actions that are solved
+ in parallel, waiting for them to complete, and then joining results).
+ </p>
+<p>
+ In order to use the classes and functions described here, you can either include
+ the specific headers specified by the descriptions of each class or function,
+ or include the master library header:
+ </p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">tp</span><span class="special">/</span><span class="identifier">tp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+</pre>
+<p>
+ which includes all the other headers in turn.
+ </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ <span class="bold"><strong>Boost.Threadpool</strong></span> uses a modified version
+ of the futures library, N2561 C++0x proposal, from Anthony Williams (http://www.justsoftwaresolutions.co.uk/threading/updated-implementation-of-c++-futures-3.html).
+ </p></td></tr>
+</table></div>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"><p><small>Last revised: March 05, 2009 at 18:12:14 GMT</small></p></td>
+<td align="right"><div class="copyright-footer"></div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav"><a accesskey="n" href="boost_threadpool/pool.html"><img src="../../doc/html/images/next.png" alt="Next"></a></div>
+</body>
+</html>
Added: sandbox/async/libs/tp/doc/introduction.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/introduction.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,24 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section Introduction]
+__boost_threadpool__ is designed for effectively utilize the available hardware and provide a way for efficient asynchronous processing of independent time consuming operations (__actions__) in the same process.
+A __threadpool__ contains a number of __worker_threads__ to perform __actions__ in parallel, which are usually managed by a scheduler. If a __worker_thread__ completes its __action__, it will take the next __action__ from the scheduler until all __actions__ have been completed. The __worker_thread__ then sleeps until there are new __actions__ available.
+Using a pool of __worker_threads__ over creating a new thread for each __action__ may result in better performance and better system stability because the overhead for thread creation and destruction is negated.
+
+__boost_threadpool__ uses a __work_stealing__ algorithm and supports __fork_join__ parallelism (recursively splitting of __actions__ into sub-actions that are solved in parallel, waiting for them to complete, and then joining results).
+
+In order to use the classes and functions described here, you can either include the specific headers specified by the descriptions of each class or function, or include the master library header:
+
+ #include <boost/tp/tp.hpp>
+
+which includes all the other headers in turn.
+
+[note
+__boost_threadpool__ uses a modified version of the futures library, N2561 C++0x proposal, from Anthony Williams ([@http://www.justsoftwaresolutions.co.uk/threading/updated-implementation-of-c++-futures-3.html]).]
+
+[endsect]
Added: sandbox/async/libs/tp/doc/meta_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/meta_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,36 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:has_priority Meta function `has_priority`]
+
+ #include <boost/tp/info.hpp>
+
+ template< typename Pool >
+ struct has_priority
+ :
+ public mpl::bool_<
+ is_same<
+ detail::has_priority,
+ typename Pool::scheduler_type::priority_tag_type
+ >::value
+ >
+ {};
+
+[endsect]
+
+
+[section:priority_type Meta function `priority_type`]
+
+ #include <boost/tp/info.hpp>
+
+ template< typename Pool >
+ struct priority_type
+ {
+ typedef typename Pool::scheduler_type::attribute_type type;
+ };
+
+[endsect]
Added: sandbox/async/libs/tp/doc/pool.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/pool.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,121 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:pool Pool]
+The pool manages internaly __worker_threads__ and submitted __actions__ are stored in a __channel__ (__global_queue__) for processing by the __worker_threads__ (using a __work_stealing__ algorithm). Each submitted __action__ gets associated with a __task__ object that will be returned. The __task__ object acts as a proxy for a result that is initially not known and gets evaluated later by a __worker_thread__.
+
+[heading Work-Stealing]
+Traditional thread poola do not scale because they use a single global queue protected by a global lock. The frequency at which __worker_threads__ aquire the global lock becomes a limiting factor for the throughput if:
+
+* the __actions__ become smaller
+* more processors are added
+
+A work-stealing algorithm can be used to solve this problem. It uses a special kind of queue which has two ends, and allows lock-free pushes and pops from the ['private end] (accessed by the __worker_thread__ owning the queue), but requires synchronization from the ['public end] (accessed by the other __worker_threads__). Synchronization is necessary when the queue is sufficiently small that private and public operations could conflict.
+
+The pool contains one global queue (__bounded_channel__ or __unbounded_channel__) protected by a global lock and each __worker_thread__ has its own private worker queue. If work is enqueued by a __worker_thread__ the __action__ is stored in the worker queue. If the work is enqueued by a application thread it goes into the global queue. When __worker_threads__ are looking for work, they have following search order:
+
+* look into the private worker queue - __actions__ can be dequeued without locks
+* look in the global queue - locks are used for synchronization
+* check other worker queues ('stealing' __actions__ from private worker queues of other __worker_threads__) - requires locks
+
+For a lot of recursively queued __actions__, the use of a worker queue per thread substantially reduces the synchronization necessary to complete the work. There are also fewer cache effects due to sharing of the global queue information.
+
+Operations on the private worker queue are executed in LIFO order and operations on worker queues of other __worker_threads__ in FIFO order (steals).
+
+* There are chances that memory is still hot in the cache, if the __actions__ are pushed in LIFO order into the private worker queue.
+* If a __worker_thread__ steals work in FIFO order, increases the chances that a larger 'chunk' of work will be stolen (the need for other steals will be possibly reduced). Because the __actions__ are stored in LIFO order, the oldest items are closer to the ['public end] of the queue (forming a tree). Stealing such an older __action__ also steals a (probably) larger subtree of __actions__ unfolded if the stolen work item get executed.
+
+[note __Actions__ submitted by a __worker_thread__ are stored into its private worker queue in LIFO order, thatswhy priorities and timeouts specified at the submit-function get ignored.]
+
+[important Because of the work-stealing algorithm the execution order of __actions__ may be not strict as in the global queue.]
+
+
+[heading Creation]
+The first template argument specifies the channel type and the scheduling policy.
+
+ boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::fifo >
+ > pool(
+ boost::tp::poolsize( 6),
+ boost::posix_time::posix_time::milliseconds( 50),
+ boost::tp::scanns(10) );
+
+In the example above a __threadpool__ is created with a __unbounded_channel__, scheduling __actions__ in ['FIFO] order. The pool contains six __worker_threads__ going to sleep for 50 millisec after 10 iterations without geting an __action__ from the __global_queue__, from its local __worker_queue__ or local queues of other __worker_threads__.
+
+ boost::tp::pool<
+ boost::tp::bounded_channel< boost::tp::priority < int > >
+ > pool(
+ boost::tp::poolsize( 10),
+ boost::tp::high_watermark( 10),
+ boost::tp::low_watermark( 5) );
+
+This pool uses a __bounded_channel__ which schedules __actions__ by integer atrributes. A maximum of 10 __actions__ can be queued in the __global_queue__ without blocking the inserting thread.
+
+
+[heading Shutdown]
+If `boost::tp::pool< Channel >::shutdown()` is called - the the status of the pool is set to ['terminating] and all __worker_threads__ are joined. No futher __actions__ can be submitted by application threads. After all pending __actions__ are processed and all __worker_threads__ are joined, the pool is set to status ['terminated].
+
+[note The deconstructor calls `boost::tp::pool< Channel >::shutdown()` if the pool was not shutdown yet.]
+
+ boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::fifo >
+ > pool( boost::tp::poolsize( 1) );
+
+ boost::tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ boost::tp::task< int > t2(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+
+ pool.shutdown();
+
+ std::cout << t1.result().get() << std::endl; // 55
+ std::cout << t2.result().get() << std::endl; // 55
+
+[heading Shutdown immediatly]
+The function `boost::tp::pool< Channel >::shutdown_now()` sets the pool status to ['terminating] interrupts and then joins all __worker_threads__. After the __worker_threads__ are joined the status of the pool is set to ['terminated] and all pending (unprocessed) __actions__ will be returned.
+
+[important Pending __actions__ in the local __worker_queues__ are not returned if `boost::tp::pool< Channel >::shutdown_now()` was called.]
+
+
+[heading Default pool]
+The free function `boost::tp::get_default_pool()` returns a reference to the default __threadpool__ instance. The default __threadpool__ is
+of type `boost::tp::pool< boost::tp::unbounded_channel< boost::tp::fifo > >` and will contain as many __worker_threads__ as
+`boost::thread::hardware_concurrency()` returns.
+
+
+[heading Meta functions]
+If the __threadpool__ supports priorities `boost::tp::has_priority< pool_type >` evaluates to `true`. The priority type is determined by `boost::tp::priority_type< pool_type >`.
+
+ typedef boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::priority< int > >
+ > pool_type;
+
+ std::cout << std::boolalpha << boost::tp::has_priority< pool_type >::value << std::endl;
+ std::cout << typeid( boost::tp::priority_type< pool_type >::type).name() << std::endl;
+
+The support of fibers can be tested with meta-function `boost::tp::has_fibers< pool_type >`.
+
+ std::cout << std::boolalpha << boost::tp::has_fibers< pool_type >::value << std::endl;
+
+[heading Processor binding]
+For some applications it is convenient to bind the worker threads of the pool to processors of the system. For this purpose BOOST_BIND_WORKER_TO_PROCESSORS must be defined. Without the poolsize in the construtor the __threadpool__ will contain as many
+__worker_threads__ as processors (== __hardware_concurrency__) are available and each __worker_thread__ is bound to one processor.
+
+ boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::fifo >
+ > pool;
+
+The code above will create a pool with two __worker_threads__ on a dual core system (each bound to one core).
+
+[endsect]
+
Added: sandbox/async/libs/tp/doc/pool_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/pool_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,349 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:pool Class template `pool`]
+
+ #include <boost/tp/pool.hpp>
+
+ template< typename Channel >
+ class pool
+ : private noncopyable
+ {
+ public:
+ explicit pool(
+ poolsize const& psize,
+ posix_time::time_duration const& asleep = posix_time::microseconds( 10),
+ scanns const& scns = scanns( 20) );
+
+ explicit pool(
+ poolsize const& psize,
+ high_watermark const& hwm,
+ low_watermark const& lwm,
+ posix_time::time_duration const& asleep = posix_time::milliseconds( 100),
+ scanns const& scns = scanns( 20) );
+
+
+ explicit pool(
+ posix_time::time_duration const& asleep = posix_time::microseconds( 10),
+ scanns const& scns = scanns( 20) );
+
+ explicit pool(
+ high_watermark const& hwm,
+ low_watermark const& lwm,
+ posix_time::time_duration const& asleep = posix_time::milliseconds( 100),
+ scanns const& scns = scanns( 20) );
+
+ ~pool();
+
+ std::size_t size();
+ std::size_t active();
+ std::size_t idle();
+
+ void shutdown();
+ const std::vector< callable > shutdown_now();
+
+ bool terminated();
+ bool terminateing();
+ void clear();
+ bool empty();
+ std::size_t pending();
+
+ const std::size_t upper_bound();
+ void upper_bound( high_watermark const& hwm);
+ const std::size_t lower_bound();
+ void lower_bound( low_watermark const& lwm);
+
+ template< typename Act >
+ task< typename result_of< Act() >::type > submit( Act const& act);
+
+ template< typename Act, typename Attr >
+ task< typename result_of< Act() >::type > submit(
+ Act const& act,
+ Attr const& attr);
+ };
+
+ pool< unbounded_channel< fifo > > & get_default_pool();
+
+[section:constructor_unbounded_channel_hw Constructor (unbounded channel)]
+
+ explicit pool(
+ posix_time::time_duration const& asleep = posix_time::microseconds( 10),
+ scanns const& scns = scanns( 20) );
+
+[variablelist
+[[Preconditions:] [Operating system provides functionality for processor pining.]]
+[[Effects:] [Constructs a `boost::tp::pool< Channel >` instance. For each processor a worker-thread is created and each worker-thread is pined exactly to one processor.]]
+[[Throws:] [`boost::tp::invalid_scanns`, `boost::tp::invalid_timeduration`]]
+[[Notes:] [Constructor has to be called if a __unbounded_channel__ is used.]]
+]
+[endsect]
+
+
+[section:constructor_unbounded_channel Constructor (unbounded channel)]
+
+ explicit pool(
+ poolsize const& psize,
+ posix_time::time_duration const& asleep = posix_time::microseconds( 10),
+ scanns const& scns = scanns( 20) );
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::pool< Channel >` instance. Pool contains psize worker-threads.]]
+[[Throws:] [`boost::tp::invalid_scanns`, `boost::tp::invalid_timeduration`]]
+[[Notes:] [Constructor has to be called if a __unbounded_channel__ is used.]]
+]
+[endsect]
+
+
+[section:constructor_bounded_channel_hw Constructor (bounded channel)]
+
+ explicit pool(
+ high_watermark const& hwm,
+ low_watermark const& lwm,
+ posix_time::time_duration const& asleep = posix_time::milliseconds( 100),
+ scanns const& scns = scanns( 20) );
+
+[variablelist
+[[Preconditions:] [Operating system provides functionality for processor pining.]]
+[[Effects:] [Constructs a `boost::tp::pool< Channel >` instance. For each processor a worker-thread is created and each worker-thread is pined exactly to one processor.]]
+[[Throws:] [`boost::tp::invalid_scanns`, `boost::tp::invalid_timeduration`, `boost::tp::invalid_watermark`]]
+[[Notes:] [Constructor has to be called if a __bounded_channel__ is used.]]
+]
+[endsect]
+
+
+[section:constructor_bounded_channel Constructor (bounded channel)]
+
+ explicit pool(
+ poolsize const& psize,
+ high_watermark const& hwm,
+ low_watermark const& lwm,
+ posix_time::time_duration const& asleep = posix_time::milliseconds( 100),
+ scanns const& scns = scanns( 20) );
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::pool< Channel >` instance. Pool contains psize worker-threads.]]
+[[Throws:] [`boost::tp::invalid_scanns`, `boost::tp::invalid_timeduration`, `boost::tp::invalid_watermark`]]
+[[Notes:] [Constructor has to be called if a __bounded_channel__ is used.]]
+]
+[endsect]
+
+
+[section:destructor Destructor]
+
+ ~pool();
+
+[variablelist
+[[Effects:] [Calls `boost::tp::pool< Channel >::shutdown()` if not yet called.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:size Member function `size()`]
+
+ std::size_t size();
+
+[variablelist
+[[Effects:] [Returns how many worker threads are running in the pool.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:active Member function `active()`]
+
+ std::size_t active();
+
+[variablelist
+[[Effects:] [Returns how many worker threads are active (executing an __action__).]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:idle Member function `idle()`]
+
+ std::size_t idle();
+
+[variablelist
+[[Effects:] [Returns how many worker threads are idle (not executing an __action__).]]
+[[Throws:] [Nothing]]
+[[Notes:] [The value is the difference of `size()` and `active()`]]
+]
+[endsect]
+
+
+[section:shutdown Member function `shutdown()`]
+
+ void shutdown();
+
+[variablelist
+[[Effects:] [Changes the pool state to ['terminating], deactivates the channel and joins all worker threads. The status of the pool is assigned to ['terminated] at the end.]]
+[[Throws:] [Nothing]]
+[[Notes:] [All pending __actions__ are processed.]]
+]
+[endsect]
+
+
+[section:shutdown_now Member function `shutdown_now()`]
+
+ const std::vector< callable > shutdown_now();
+
+[variablelist
+[[Effects:] [Changes the pool state to ['terminating], deactivates the channel, send interruption request to all worker threads and joins them. The status of the pool is assigned to ['terminated] at the end.]]
+[[Throws:] [Nothing]]
+[[Notes:] [Pending __actions__ are not processed but returned.]]
+]
+[endsect]
+
+
+[section:terminated Member function `terminated()`]
+
+ bool terminated();
+
+[variablelist
+[[Effects:] [Queries if the pool is in the terminated state (pool is shutdown).]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:terminateing Member function `terminateing()`]
+
+ bool terminateing();
+
+[variablelist
+[[Effects:] [Queries if the pool is in the terminating state (tries to shutdown the pool).]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:clear Member function `clear()`]
+
+ void clear();
+
+[variablelist
+[[Effects:] [Removes all pending __actions__ from the __channel__.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:empty Member function `empty()`]
+
+ bool empty();
+
+[variablelist
+[[Effects:] [Queries if the __channel__ is empty.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:pending Member function `pending()`]
+
+ std::size_t pending();
+
+[variablelist
+[[Effects:] [Queries how many __actions__ are pending in the __channel__.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:get_upper_bound Member function `upper_bound()`]
+
+ std::size_t upper_bound();
+
+[variablelist
+[[Preconditions:] [Channel is of type __bounded_channel__.]]
+[[Effects:] [Returns the upper bound of the __bounded_channel__.]]
+[[Throws:] [Nothing]]
+[[Notes:] [Can only be used if a __bounded_channel__ is used.]]
+]
+[endsect]
+
+
+[section:set_upper_bound Member function `upper_bound( high_watermark const& hwm)`]
+
+ void upper_bound( high_watermark const& hwm);
+
+[variablelist
+[[Preconditions:] [Channel is of type __bounded_channel__.]]
+[[Effects:] [Sets the upper bound of the __bounded_channel__.]]
+[[Postconditions:] [`this->upper_bound() == hwm`.]]
+[[Throws:] [`boost::tp::invalid_watermark`]]
+[[Notes:] [Can only be used if a __bounded_channel__ is used.]]
+]
+[endsect]
+
+
+[section:get_lower_bound Member function `lower_bound()`]
+
+ std::size_t lower_bound();
+
+[variablelist
+[[Preconditions:] [Channel is of type __bounded_channel__.]]
+[[Effects:] [Returns the lower bound of the __bounded_channel__.]]
+[[Throws:] [Nothing]]
+[[Notes:] [Can only be used if a __bounded_channel__ is used.]]
+]
+[endsect]
+
+
+[section:set_lower_bound Member function `lower_bound( low_watermark const& lwm)`]
+
+ void lower_bound( low_watermark const& lwm);
+
+[variablelist
+[[Preconditions:] [Channel is of type __bounded_channel__.]]
+[[Effects:] [Sets the lower bound of the __bounded_channel__.]]
+[[Postconditions:] [`this->lower_bound() == lwm`.]]
+[[Throws:] [`boost::tp::invalid_watermark`]]
+[[Notes:] [Can only be used if a __bounded_channel__ is used.]]
+]
+[endsect]
+
+
+[section:submit Member function `submit( Act const& act)`]
+
+ template< typename Act >
+ task< typename result_of< Act() >::type > submit( Act const& act);
+
+[variablelist
+[[Preconditions:] [has_priority< pool >::value == false && ! ( pool.terminating() || pool.terminated() )]]
+[[Effects:] [Submits an __action__ to the pool and returns a __task__ object.]]
+[[Throws:] [`boost::tp::task_rejected`]]
+]
+[endsect]
+
+
+[section:submit_attr Member function `submit( Act const& act, Attr const& attr)`]
+
+ template< typename Act, typename Attr >
+ task< typename result_of< Act() >::type > submit( Act const& act, Attr const& attr);
+
+[variablelist
+[[Preconditions:] [has_priority< pool >::value == true && ! ( pool.terminating() || pool.terminated() )]]
+[[Effects:] [Submits an __action__ to the pool and returns a __task__ object. __Action__ is scheduled by the attribute.]]
+[[Throws:] [`boost::tp::task_rejected`]]
+]
+[endsect]
+
+
+[section:get_default_pool Non-member function `get_default_pool()`]
+
+ pool< unbounded_channel< fifo > > & get_default_pool();
+
+[variablelist
+[[Effects:] [Get access to default thread pool (static).]]
+]
+[endsect]
+
+
+[endsect]
Added: sandbox/async/libs/tp/doc/poolsize_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/poolsize_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,43 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:poolsize Class `poolsize`]
+
+ #include <boost/tp/poolsize.hpp>
+
+ class poolsize
+ {
+ public:
+ explicit poolsize( std::size_t value);
+
+ operator std::size_t () const;
+ };
+
+[section:constructor Constructor]
+
+ explicit poolsize( std::size_t value);
+
+[variablelist
+[[Preconditions:][value > 0]]
+[[Effects:] [Constructs a `boost::tp::poolsize` instance.]]
+[[Postconditions:][operator std::size_t () > 0]]
+[[Throws:] [`boost::tp::invalid_poolsize`]]
+]
+[endsect]
+
+
+[section:operator Member function `operator std::size_t()`]
+
+ operator std::size_t () const;
+
+[variablelist
+[[Effects:] [Returns pool size.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
Added: sandbox/async/libs/tp/doc/reference.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/reference.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,19 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:reference Reference]
+
+[include pool_ref.qbk]
+[include task_ref.qbk]
+[include this_task_ref.qbk]
+[include poolsize_ref.qbk]
+[include scanns_ref.qbk]
+[include watermark_ref.qbk]
+[include exceptions_ref.qbk]
+[include meta_ref.qbk]
+
+[endsect]
Added: sandbox/async/libs/tp/doc/scanns_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/scanns_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,42 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:scanns Class `scanns`]
+
+ #include <boost/tp/scanns.hpp>
+
+ class scanns
+ {
+ public:
+ explicit scanns( std::size_t value);
+
+ operator std::size_t () const;
+ };
+
+[section:constructor Constructor]
+
+ explicit scanns( std::size_t value);
+
+[variablelist
+[[Preconditions:][value >= 0]]
+[[Effects:] [Constructs a `boost::tp::scanns` instance.]]
+[[Postconditions:][operator std::size_t () >= 0]]
+[[Throws:] [`boost::tp::invalid_scanns`]]
+]
+[endsect]
+
+[section:operator Member function `operator std::size_t()`]
+
+ operator std::size_t () const;
+
+[variablelist
+[[Effects:] [Returns scanns size.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
Added: sandbox/async/libs/tp/doc/scheduling.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/scheduling.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,84 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:scheduling Scheduling]
+The scheduling policy determines how __actions__ are scheduled inside the __channel__.
+
+[heading fifo]
+
+ struct fifo
+
+First inserted pending __action__ get taken first.
+
+
+[heading lifo]
+
+ struct lifo
+
+Last inserted pending __action__ get taken first.
+
+
+[heading priority]
+
+ template< typename Attr, typename Ord = std::less< Attr > > struct priority
+
+Each pending task is associated with a priority attribute which is used for ordering __actions__.
+
+
+[heading smart]
+
+ template< typename Attr, typename Ord, typename Enq, typename Deq > struct smart
+
+Each pending __actions__ is associated with an attribute. The scheduler gets an put- and take-policy
+as template arguments. The corresponding policy get applied for each insertion and removal.
+
+__boost_threadpool__ provides ['boost::tp::replace_oldest] as put policy and ['boost::tp::take_oldest] as take
+policy. Both policies allow the replacement of old __actions__ in the scheduler by new ones.
+
+ // creates a pool with unbounded channel
+ // tasks are processed depending on the associated attributed
+ // oldest tasks with the same attributed pending in the channel
+ // will be replaced by the new task
+ // this example would execute add( 1, 2) and add( 5, 6)
+ // add( 2, 3) is removed (if pending when add( 5, 6) is submitted)
+ boost::tp::pool<
+ boost::tp::unbounded_channel<
+ boost::tp::smart<
+ int,
+ std::less< int >,
+ boost::tp::replace_oldest,
+ boost::tp::take_oldest
+ >
+ >
+ > pool( boost::tp::poolsize( 1) );
+
+ pool.submit(
+ boost::bind(
+ add_fn,
+ 1,
+ 2),
+ 0);
+
+ // replaced by later task with same attribute
+ // if still pending in pool
+ pool.submit(
+ boost::bind(
+ add_fn,
+ 3,
+ 4),
+ 1);
+
+ // will replace previous pending action
+ pool.submit(
+ boost::bind(
+ add_fn,
+ 5,
+ 6),
+ 1);
+
+
+[endsect]
Added: sandbox/async/libs/tp/doc/stacksize_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/stacksize_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,42 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:stacksize Class `stacksize`]
+
+ #include <boost/tp/stacksize.hpp>
+
+ class stacksize
+ {
+ public:
+ explicit stacksize( std::size_t value);
+
+ operator std::size_t () const;
+ };
+
+[section:constructor Constructor]
+
+ explicit stacksize( std::size_t value);
+
+[variablelist
+[[Preconditions:][value > 0]]
+[[Effects:] [Constructs a `boost::tp::stacksize` instance.]]
+[[Postconditions:][operator std::size_t () > 0]]
+[[Throws:] [`boost::tp::invalid_stacksize`]]
+]
+[endsect]
+
+[section:operator Member function `operator std::size_t()`]
+
+ operator std::size_t () const;
+
+[variablelist
+[[Effects:] [Returns stack size.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
Added: sandbox/async/libs/tp/doc/task.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/task.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,122 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:task Task]
+For each submitted __action__ a new task object will be created and returned by the pool.
+The __task__ object acts as a proxy for a result that is initially not known and gets evaluated later by a __worker_thread__. It transports the result (value or exception) of the __action__ back to the caller.
+
+ boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::fifo >
+ > pool( boost::tp::poolsize( 10) );
+
+ // task calculates fibonacci(10)
+ // scheduled in unbounded channel with FIFO ordering
+ boost::tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+
+ std::cout << t.result().get() << std::endl; // 55
+
+
+[heading Interruption]
+The returned __task__ object provides the possiblity to interrupt an __action__ if it is cooperative.
+An __action__ is known as cooperative if it includes interruption points in its code:
+
+* `boost::thread::join()`
+* `boost::thread::timed_join()`
+* `boost::condition_variable::wait()`
+* `boost::condition_variable::timed_wait()`
+* `boost::condition_variable_any::wait()`
+* `boost::condition_variable_any::timed_wait()`
+* `boost::thread::sleep()`
+* `boost::this_thread::sleep()`
+* `boost::this_thread::interruption_point()`
+
+[important Interruption must not be disabled for the __worker_thread__ (class ['boost::this_thread::disable_interruption]).]
+
+The __action__ will be interrupted even if it is pending (interruption is remembered).
+A ['boost::thread_interrupted] exception will be thrown by `boost::tp::task< T >::get()` if the __action__ was interrupted.
+``
+ boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::fifo >
+ > pool( boost::tp::poolsize( 10) );
+
+ // submit a long running task
+ boost::tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ long_running_fn) ) );
+
+ // interrupt task
+ t.interrupt();
+
+ // throws boost::thread_interrupted exception
+ std::cout << t.result().get() << std::endl;
+``
+
+ boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::fifo >
+ > pool( boost::tp::poolsize( 10) );
+
+ // submit a long running task
+ boost::tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ long_running_fn) ) );
+
+ // interrupt task and wait for its termination
+ t.interrupt_and_wait();
+
+ // throws boost::thread_interrupted exception
+ std::cout << t.result().get() << std::endl;
+
+[heading Exceptions in tasks]
+Exceptions thrown inside an __action__ are transported by the associated task object.
+Exceptions rethrown by type:
+
+* `std::bad_alloc`
+* `std::bad_cast`
+* `std::bad_exception`
+* `std::bad_typeid`
+* `std::domain_error`
+* `std::invalid_argument`
+* `std::ios_base::failure`
+* `std::length_error`
+* `std::logic_error`
+* `std::out_of_range`
+* `std::overflow_error`
+* `std::range_error`
+* `std::runtime_error`
+* `std::underflow_error`
+* `boost::broken_promise`
+* `boost::future_already_set`
+* `boost::future_cancel`
+* `boost::invalid_thread_argument`
+* `boost::lock_error`
+* `boost::thread_exception`
+* `boost::thread_interrupted`
+* `boost::thread_permission_error`
+* `boost::thread_resource_error`
+* `boost::unsupported_thread_option`
+
+Exceptions derived from `std::exception` will be rethrown as `std::runtime_error` in all other cases a `std::bad_exception` is thrown.
+
+ boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::fifo >
+ > pool( boost::tp::poolsize( 10) );
+
+ // task will throw an exception derived from std::exception
+ boost::tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn) ) );
+
+ std::cout << t.result().get() << std::endl; // will rethrow an std::runtime_error
+
+[endsect]
Added: sandbox/async/libs/tp/doc/task_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/task_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,86 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:task Class template `task`]
+
+ #include <boost/tp/task.hpp>
+
+ template< typename R >
+ class task
+ {
+ public:
+ template< typename Pool >
+ task(
+ Pool * pool,
+ shared_future< R > const& fut,
+ detail::interrupter const& intr);
+
+ void interrupt();
+ void interrupt_and_wait();
+ void interrupt_and_wait( system_time const& abs_time);
+ template< typename Duration >
+ void interrupt_and_wait( Duration const& rel_time);
+ bool interrupt_requested();
+
+ shared_future< R > result() const;
+ };
+
+[section:constructor Constructor]
+
+ template< typename Pool >
+ task(
+ Pool * pool,
+ shared_future< R > const& fut,
+ detail::interrupter const& intr);
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::task< R >` instance.]]
+[[Throws:] [Nothing]]
+[[Notes:] [task objects should only be constructed by the pool.]]
+]
+[endsect]
+
+
+[section:interrupt Member function `interrupt()`]
+
+ void interrupt();
+
+[variablelist
+[[Effects:] [Associated __action__ will be interrupted the next time it enters a __interruption_point__ if interruption is not disabled. The function returns immediatly.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:interrupt_and_wait Member function `interrupt_and_wait()`]
+
+ void interrupt_and_wait();
+
+ void interrupt_and_wait( system_time const& abs_time);
+
+ template< typename DurationTime >
+ void interrupt_and_wait( DurationTime const& rel_time);
+
+[variablelist
+[[Effects:] [Associated __action__ will be interrupted the next time it enters one __interruption_point__ if interruption is not disabled. The function waits until the __action__ has terminated or the specified duration td has elapsed.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:result Member function `result()`]
+
+ shared_future< R > result() const;
+
+[variablelist
+[[Effects:] [Returns fulfilled value or throws fulfilled exception via a shared_future.]]
+[[Throws:] [`boost::future::broken_promise`]]
+]
+[endsect]
+
+
+[endsect]
Added: sandbox/async/libs/tp/doc/this_task.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/this_task.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,16 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:this_task Namespace this_task]
+In the function `boost::this_task::reschedule_until( Pred const&)` allows to synchronize the task with other
+asynchronous events without blocking the __worker_threads__ (bool Pred::operator()() must not block)
+The current task will be rescheduled until the passed predicate becomes true.
+The pool can be accessed via `boost::this_task::get_thread_pool< Pool >()` if the calling code is executed by a __worker_thread__.
+`boost::this_task::s_worker()` evaluates true if the current thread is __worker_thread__ and `boost::this_task::worker_id()`
+returns the thread id.
+
+[endsect]
Added: sandbox/async/libs/tp/doc/this_task_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/this_task_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,64 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:reschedule_until Non-member function `reschedule_until()`]
+
+ #include <boost/tp/pool.hpp>
+
+ template< typename Pred >
+ void reschedule_until( Pred const&);
+
+[variablelist
+[[Effects:] [Reschedules current task until passed callable predicate becomes ready.]
+[[Throws:] [Nothing.]]
+[[Note:] [This function resides in namespace `boost::this_task`.]]
+]
+
+[endsect]
+
+[section:get_thread_pool Non-member function `get_thread_pool()`]
+
+ #include <boost/tp/pool.hpp>
+
+ template< typename Pool >
+ Pool & get_thread_pool();
+
+[variablelist
+[[Effects:] [Returns reference to the thread pool where the current worker thread is running.]
+[[Throws:] [Nothing.]]
+[[Note:] [This function resides in namespace `boost::this_task`.]]
+]
+
+[endsect]
+
+[section:is_worker Non-member function `is_worker()`]
+
+ #include <boost/tp/pool.hpp>
+
+ bool is_worker();
+
+[variablelist
+[[Effects:] [Returns true if the current thread is a worker-thread form a pool.]
+[[Throws:] [Nothing.]]
+[[Note:] [This function resides in namespace `boost::this_task`.]]
+]
+
+[endsect]
+
+[section:worker_id Non-member function `worker_id()`]
+
+ #include <boost/tp/pool.hpp>
+
+ thread::id worker_id();
+
+[variablelist
+[[Effects:] [Returns returns the thread-id of the worker-thread.]
+[[Throws:] [Nothing.]]
+[[Note:] [This function resides in namespace `boost::this_task`.]]
+]
+
+[endsect]
Added: sandbox/async/libs/tp/doc/threadpool.qbk
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/threadpool.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,59 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[library Boost.Threadpool
+ [quickbook 1.4]
+ [copyright 2008 Oliver Kowalke]
+ [purpose C++ Library for executing actions in a pool of worker threads]
+ [license
+ 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])
+ ]
+ [authors [Kowalke, Oliver]]
+ [category text]
+]
+
+
+[def __action__ action]
+[def __actions__ actions]
+[def __Actions__ Actions]
+[def __boost__ [*boost-1.37.0]]
+[def __boost_future__ [*Boost.Future]]
+[def __boost_threadpool__ [*Boost.Threadpool]]
+[def __bounded_channel__ [link boost_threadpool.channel.bounded_channel ['bounded channel]]]
+[def __unbounded_channel__ [link boost_threadpool.channel.unbounded_channel ['unbounded channel]]]
+[def __channel__ [link boost_threadpool.channel ['channel]]]
+[def __channels__ [link boost_threadpool.channel ['channels]]]
+[def __fork_join__ [link boost_threadpool.forkjoin ['fork/join]]]
+[def __global_queue__ [link boost_threadpool.pool.work_stealing ['global queue]]]
+[def __hardware_concurrency__ boost::thread::hardware_concurrency]
+[def __hwm__ high watermark]
+[def __interruption_point__ [link boost_threadpool.task.interruption ['interruption point]]]
+[def __lwm__ low watermark]
+[def __scheduler_type__ [link boost_threadpool.scheduling ['scheduler type]]]
+[def __sub_action__ sub_action]
+[def __sub_actions__ sub_actions]
+[def __task__ [link boost_threadpool.task ['task]]]
+[def __tasks__ [link boost_threadpool.task ['tasks]]]
+[def __threadpool__ thread pool]
+[def __work_stealing__ [link boost_threadpool.pool.work_stealing ['work stealing]]]
+[def __worker_queue__ [link boost_threadpool.pool.work_stealing ['worker queue]]]
+[def __worker_queues__ [link boost_threadpool.pool.work_stealing ['worker queues]]]
+[def __worker_thread__ worker thread]
+[def __worker_threads__ worker threads]
+
+
+[include introduction.qbk]
+[include pool.qbk]
+[include task.qbk]
+[include this_task.qbk]
+[include channel.qbk]
+[include scheduling.qbk]
+[include forkjoin.qbk]
+[include acknowledgement.qbk]
+[include reference.qbk]
Added: sandbox/async/libs/tp/doc/threadpool.xml
Added: sandbox/async/libs/tp/doc/watermark_ref.qbk
Added: sandbox/async/libs/tp/examples/Jamfile.v2
Added: sandbox/async/libs/tp/examples/fork_join.cpp
Added: sandbox/async/libs/tp/examples/interrupt.cpp
Added: sandbox/async/libs/tp/examples/parallel_sort.cpp
Added: sandbox/async/libs/tp/examples/pending.cpp
Added: sandbox/async/libs/tp/examples/priority.cpp
Added: sandbox/async/libs/tp/examples/reschedule_until.cpp
Added: sandbox/async/libs/tp/examples/shutdonw_now.cpp
Added: sandbox/async/libs/tp/examples/smart.cpp
Added: sandbox/async/libs/tp/examples/spread_over_hardware.cpp
Added: sandbox/async/libs/tp/examples/submit.cpp
Added: sandbox/async/libs/tp/src/callable.cpp
Added: sandbox/async/libs/tp/src/default_pool.cpp
Added: sandbox/async/libs/tp/src/guard.cpp
Added: sandbox/async/libs/tp/src/interrupter.cpp
Added: sandbox/async/libs/tp/src/poolsize.cpp
Added: sandbox/async/libs/tp/src/scanns.cpp
Added: sandbox/async/libs/tp/src/watermark.cpp
Added: sandbox/async/libs/tp/src/worker.cpp
Added: sandbox/async/libs/tp/test/Jamfile.v2
Added: sandbox/async/libs/tp/test/test_bounded_queue_fifo.cpp
Added: sandbox/async/libs/tp/test/test_bounded_queue_lifo.cpp
Added: sandbox/async/libs/tp/test/test_bounded_queue_priority.cpp
Added: sandbox/async/libs/tp/test/test_bounded_queue_smart.cpp
Added: sandbox/async/libs/tp/test/test_functions.hpp
Added: sandbox/async/libs/tp/test/test_unbounded_queue_fifo.cpp
Added: sandbox/async/libs/tp/test/test_unbounded_queue_lifo.cpp
Added: sandbox/async/libs/tp/test/test_unbounded_queue_priority.cpp
Added: sandbox/async/libs/tp/test/test_unbounded_queue_smart.cpp
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
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/threadpool.xml 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,3014 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<library id="boost_threadpool" name="Boost.Threadpool" dirname="boost_threadpool"
+last-revision="$Date: 2009/03/03 21:18:36 $" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <libraryinfo>
+ <authorgroup>
+ <author>
+ <firstname>Oliver</firstname> <surname>Kowalke</surname>
+ </author>
+ </authorgroup>
+ <copyright>
+ <year>2008</year> <holder>Oliver Kowalke</holder>
+ </copyright>
+ <legalnotice>
+ <para>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at <ulink url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt>)
+ </para>
+ </legalnotice>
+ <librarypurpose>
+ C++ Library for executing actions in a pool of worker threads
+ </librarypurpose>
+ <librarycategory name="category:text"></librarycategory>
+ </libraryinfo>
+ <title>Boost.Threadpool</title>
+ <section id="boost_threadpool.introduction">
+ <title><link linkend="boost_threadpool.introduction">Introduction</link></title>
+ <para>
+ <emphasis role="bold">Boost.Threadpool</emphasis> is designed for effectively
+ utilize the available hardware and provide a way for efficient asynchronous
+ processing of independent time consuming operations (actions) in the same process.
+ A thread pool contains a number of worker threads to perform actions in parallel,
+ which are usually managed by a scheduler. If a worker thread completes its
+ action, it will take the next action from the scheduler until all actions have
+ been completed. The worker thread then sleeps until there are new actions available.
+ Using a pool of worker threads over creating a new thread for each action may
+ result in better performance and better system stability because the overhead
+ for thread creation and destruction is negated.
+ </para>
+ <para>
+ <emphasis role="bold">Boost.Threadpool</emphasis> uses a <link linkend="boost_threadpool.pool.work_stealing"><emphasis>work
+ stealing</emphasis></link> algorithm and supports <link linkend="boost_threadpool.forkjoin"><emphasis>fork/join</emphasis></link>
+ parallelism (recursively splitting of actions into sub-actions that are solved
+ in parallel, waiting for them to complete, and then joining results).
+ </para>
+ <para>
+ In order to use the classes and functions described here, you can either include
+ the specific headers specified by the descriptions of each class or function,
+ or include the master library header:
+ </para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+</programlisting>
+ <para>
+ which includes all the other headers in turn.
+ </para>
+ <note>
+ <para>
+ <emphasis role="bold">Boost.Threadpool</emphasis> uses a modified version
+ of the futures library, N2561 C++0x proposal, from Anthony Williams (<ulink
+ url="http://www.justsoftwaresolutions.co.uk/threading/updated-implementation-of-c++-futures-3.html">http://www.justsoftwaresolutions.co.uk/threading/updated-implementation-of-c++-futures-3.html>).
+ </para>
+ </note>
+ </section>
+ <section id="boost_threadpool.pool">
+ <title><link linkend="boost_threadpool.pool"> Pool</link></title>
+ <para>
+ The pool manages internaly worker threads and submitted actions are stored
+ in a <link linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>
+ (<link linkend="boost_threadpool.pool.work_stealing"><emphasis>global queue</emphasis></link>)
+ for processing by the worker threads (using a <link linkend="boost_threadpool.pool.work_stealing"><emphasis>work
+ stealing</emphasis></link> algorithm). Each submitted action gets associated
+ with a <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
+ object that will be returned. The <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
+ object acts as a proxy for a result that is initially not known and gets evaluated
+ later by a worker thread.
+ </para>
+ <anchor id="boost_threadpool.pool.work_stealing"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.pool.work_stealing">Work-Stealing</link>
+ </bridgehead>
+ <para>
+ Traditional thread poola do not scale because they use a single global queue
+ protected by a global lock. The frequency at which worker threads aquire the
+ global lock becomes a limiting factor for the throughput if:
+ </para>
+ <itemizedlist>
+ <listitem>
+ the actions become smaller
+ </listitem>
+ <listitem>
+ more processors are added
+ </listitem>
+ </itemizedlist>
+ <para>
+ A work-stealing algorithm can be used to solve this problem. It uses a special
+ kind of queue which has two ends, and allows lock-free pushes and pops from
+ the <emphasis>private end</emphasis> (accessed by the worker thread owning
+ the queue), but requires synchronization from the <emphasis>public end</emphasis>
+ (accessed by the other worker threads). Synchronization is necessary when the
+ queue is sufficiently small that private and public operations could conflict.
+ </para>
+ <para>
+ The pool contains one global queue (<link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link> or <link linkend="boost_threadpool.channel.unbounded_channel"><emphasis>unbounded
+ channel</emphasis></link>) protected by a global lock and each worker thread
+ has its own private worker queue. If work is enqueued by a worker thread the
+ action is stored in the worker queue. If the work is enqueued by a application
+ thread it goes into the global queue. When worker threads are looking for work,
+ they have following search order:
+ </para>
+ <itemizedlist>
+ <listitem>
+ look into the private worker queue - actions can be dequeued without locks
+ </listitem>
+ <listitem>
+ look in the global queue - locks are used for synchronization
+ </listitem>
+ <listitem>
+ check other worker queues ('stealing' actions from private worker queues
+ of other worker threads) - requires locks
+ </listitem>
+ </itemizedlist>
+ <para>
+ For a lot of recursively queued actions, the use of a worker queue per thread
+ substantially reduces the synchronization necessary to complete the work. There
+ are also fewer cache effects due to sharing of the global queue information.
+ </para>
+ <para>
+ Operations on the private worker queue are executed in LIFO order and operations
+ on worker queues of other worker threads in FIFO order (steals).
+ </para>
+ <itemizedlist>
+ <listitem>
+ There are chances that memory is still hot in the cache, if the actions are
+ pushed in LIFO order into the private worker queue.
+ </listitem>
+ <listitem>
+ If a worker thread steals work in FIFO order, increases the chances that
+ a larger 'chunk' of work will be stolen (the need for other steals will be
+ possibly reduced). Because the actions are stored in LIFO order, the oldest
+ items are closer to the <emphasis>public end</emphasis> of the queue (forming
+ a tree). Stealing such an older action also steals a (probably) larger subtree
+ of actions unfolded if the stolen work item get executed.
+ </listitem>
+ </itemizedlist>
+ <note>
+ <para>
+ Actions submitted by a worker thread are stored into its private worker queue
+ in LIFO order, thatswhy priorities and timeouts specified at the submit-function
+ get ignored.
+ </para>
+ </note>
+ <important>
+ <para>
+ Because of the work-stealing algorithm the execution order of actions may
+ be not strict as in the global queue.
+ </para>
+ </important>
+ <anchor id="boost_threadpool.pool.creation"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.pool.creation">Creation</link>
+ </bridgehead>
+ <para>
+ The first template argument specifies the channel type and the scheduling policy.
+ </para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">6</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">50</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">scanns</phrase><phrase role="special">(</phrase><phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ <para>
+ In the example above a thread pool is created with a <link linkend="boost_threadpool.channel.unbounded_channel"><emphasis>unbounded
+ channel</emphasis></link>, scheduling actions in <emphasis>FIFO</emphasis>
+ order. The pool contains six worker threads going to sleep for 50 millisec
+ after 10 iterations without geting an action from the <link linkend="boost_threadpool.pool.work_stealing"><emphasis>global
+ queue</emphasis></link>, from its local <link linkend="boost_threadpool.pool.work_stealing"><emphasis>worker
+ queue</emphasis></link> or local queues of other worker threads.
+ </para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">bounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">priority</phrase> <phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">high_watermark</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">low_watermark</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ <para>
+ This pool uses a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link> which schedules actions by integer atrributes. A
+ maximum of 10 actions can be queued in the <link linkend="boost_threadpool.pool.work_stealing"><emphasis>global
+ queue</emphasis></link> without blocking the inserting thread.
+ </para>
+ <anchor id="boost_threadpool.pool.shutdown"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.pool.shutdown">Shutdown</link>
+ </bridgehead>
+ <para>
+ If <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">Channel</phrase> <phrase
+ role="special">>::</phrase><phrase role="identifier">shutdown</phrase><phrase
+ role="special">()</phrase></code> is called - the the status of the pool is
+ set to <emphasis>terminating</emphasis> and all worker threads are joined.
+ No futher actions can be submitted by application threads. After all pending
+ actions are processed and all worker threads are joined, the pool is set to
+ status <emphasis>terminated</emphasis>.
+ </para>
+ <note>
+ <para>
+ The deconstructor calls <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase
+ role="identifier">Channel</phrase> <phrase role="special">>::</phrase><phrase
+ role="identifier">shutdown</phrase><phrase role="special">()</phrase></code>
+ if the pool was not shutdown yet.
+ </para>
+ </note>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">shutdown</phrase><phrase role="special">();</phrase>
+
+<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// 55
+</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// 55
+</phrase></programlisting>
+ <anchor id="boost_threadpool.pool.shutdown_immediatly"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.pool.shutdown_immediatly">Shutdown immediatly</link>
+ </bridgehead>
+ <para>
+ The function <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">Channel</phrase> <phrase
+ role="special">>::</phrase><phrase role="identifier">shutdown_now</phrase><phrase
+ role="special">()</phrase></code> sets the pool status to <emphasis>terminating</emphasis>
+ interrupts and then joins all worker threads. After the worker threads are
+ joined the status of the pool is set to <emphasis>terminated</emphasis> and
+ all pending (unprocessed) actions will be returned.
+ </para>
+ <important>
+ <para>
+ Pending actions in the local <link linkend="boost_threadpool.pool.work_stealing"><emphasis>worker
+ queues</emphasis></link> are not returned if <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase
+ role="identifier">Channel</phrase> <phrase role="special">>::</phrase><phrase
+ role="identifier">shutdown_now</phrase><phrase role="special">()</phrase></code>
+ was called.
+ </para>
+ </important>
+ <anchor id="boost_threadpool.pool.default_pool"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.pool.default_pool">Default pool</link>
+ </bridgehead>
+ <para>
+ The free function <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">get_default_pool</phrase><phrase
+ role="special">()</phrase></code> returns a reference to the default thread
+ pool instance. The default thread pool is of type <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase
+ role="special">></phrase></code> and will contain as many worker threads
+ as <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">hardware_concurrency</phrase><phrase role="special">()</phrase></code>
+ returns.
+ </para>
+ <anchor id="boost_threadpool.pool.meta_functions"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.pool.meta_functions">Meta functions</link>
+ </bridgehead>
+ <para>
+ If the thread pool supports priorities <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">has_priority</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="special">></phrase></code>
+ evaluates to <code><phrase role="keyword">true</phrase></code>. The priority
+ type is determined by <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">priority_type</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="special">></phrase></code>.
+ </para>
+
+<programlisting><phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">priority</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
+
+<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">has_priority</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>::</phrase><phrase role="identifier">value</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="keyword">typeid</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">priority_type</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase><phrase role="special">).</phrase><phrase role="identifier">name</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <para>
+ The support of fibers can be tested with meta-function <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">has_fibers</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="special">></phrase></code>.
+ </para>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">has_fibers</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>::</phrase><phrase role="identifier">value</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <anchor id="boost_threadpool.pool.processor_binding"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.pool.processor_binding">Processor binding</link>
+ </bridgehead>
+ <para>
+ For some applications it is convenient to bind the worker threads of the pool
+ to processors of the system. For this purpose BOOST_BIND_WORKER_TO_PROCESSORS
+ must be defined. Without the poolsize in the construtor the thread pool will
+ contain as many worker threads as processors (== boost::thread::hardware_concurrency)
+ are available and each worker thread is bound to one processor.
+ </para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
+ <phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <para>
+ The code above will create a pool with two worker threads on a dual core system
+ (each bound to one core).
+ </para>
+ </section>
+ <section id="boost_threadpool.task">
+ <title><link linkend="boost_threadpool.task"> Task</link></title>
+ <para>
+ For each submitted action a new task object will be created and returned by
+ the pool. The <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
+ object acts as a proxy for a result that is initially not known and gets evaluated
+ later by a worker thread. It transports the result (value or exception) of
+ the action back to the caller.
+ </para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="comment">// task calculates fibonacci(10)
+</phrase><phrase role="comment">// scheduled in unbounded channel with FIFO ordering
+</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
+<phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// 55
+</phrase></programlisting>
+ <anchor id="boost_threadpool.task.interruption"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.task.interruption">Interruption</link>
+ </bridgehead>
+ <para>
+ The returned <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
+ object provides the possiblity to interrupt an action if it is cooperative.
+ An action is known as cooperative if it includes interruption points in its
+ code:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">join</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">timed_join</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">condition_variable</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">wait</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">condition_variable</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">timed_wait</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">condition_variable_any</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">wait</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">condition_variable_any</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">timed_wait</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">sleep</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">this_thread</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">sleep</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">this_thread</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">interruption_point</phrase><phrase role="special">()</phrase></code>
+ </listitem>
+ </itemizedlist>
+ <important>
+ <para>
+ Interruption must not be disabled for the worker thread (class <emphasis>boost::this_thread::disable_interruption</emphasis>).
+ </para>
+ </important>
+ <para>
+ The action will be interrupted even if it is pending (interruption is remembered).
+ A <emphasis>boost::thread_interrupted</emphasis> exception will be thrown by
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">T</phrase> <phrase role="special">>::</phrase><phrase
+ role="identifier">get</phrase><phrase role="special">()</phrase></code> if
+ the action was interrupted.
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="comment">// submit a long running task
+</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">long_running_fn</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="comment">// interrupt task
+</phrase><phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">interrupt</phrase><phrase role="special">();</phrase>
+
+<phrase role="comment">// throws boost::thread_interrupted exception
+</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+</programlisting>
+ </para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="comment">// submit a long running task
+</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">long_running_fn</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="comment">// interrupt task and wait for its termination
+</phrase><phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">();</phrase>
+
+<phrase role="comment">// throws boost::thread_interrupted exception
+</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <anchor id="boost_threadpool.task.exceptions_in_tasks"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.task.exceptions_in_tasks">Exceptions in tasks</link>
+ </bridgehead>
+ <para>
+ Exceptions thrown inside an action are transported by the associated task object.
+ Exceptions rethrown by type:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">bad_alloc</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">bad_cast</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">bad_exception</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">bad_typeid</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">domain_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_argument</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">ios_base</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">failure</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">length_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">logic_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">out_of_range</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">overflow_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">range_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">runtime_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">underflow_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">broken_promise</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">future_already_set</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">future_cancel</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_thread_argument</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">lock_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread_exception</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread_interrupted</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread_permission_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread_resource_error</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">unsupported_thread_option</phrase></code>
+ </listitem>
+ </itemizedlist>
+ <para>
+ Exceptions derived from <code><phrase role="identifier">std</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">exception</phrase></code>
+ will be rethrown as <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">runtime_error</phrase></code> in all other cases a <code><phrase
+ role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bad_exception</phrase></code>
+ is thrown.
+ </para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="comment">// task will throw an exception derived from std::exception
+</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">throwing_fn</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// will rethrow an std::runtime_error
+</phrase></programlisting>
+ </section>
+ <section id="boost_threadpool.this_task">
+ <title><link linkend="boost_threadpool.this_task"> Namespace this_task</link></title>
+ <para>
+ In the function <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">reschedule_until</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">shared_future</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">R</phrase> <phrase role="special">></phrase>
+ <phrase role="keyword">const</phrase><phrase role="special">&)</phrase></code>
+ allows to synchronize the task with other asynchronous events without blocking
+ the worker threads. The current task will be rescheduled until the passed future
+ becomes ready. The pool can be accessed via <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">Pool</phrase> <phrase
+ role="special">>()</phrase></code> if the calling code is executed by a
+ worker thread.
+ </para>
+ </section>
+ <section id="boost_threadpool.channel">
+ <title><link linkend="boost_threadpool.channel"> Channel</link></title>
+ <para>
+ The channel synchronizes the access between application threads (producer threads)
+ submitting actions to the pool and worker threads (consumer threads). The scheduling
+ of actions queued into the channel depends on channels the scheduling policy.
+ If the channel becomes empty all worker threads are set to sleep until a new
+ action is put in.
+ </para>
+ <anchor id="boost_threadpool.channel.bounded_channel"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.channel.bounded_channel">bounded channel</link>
+ </bridgehead>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">SchedulingPolicy</phrase> <phrase role="special">></phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">bounded_channel</phrase>
+</programlisting>
+ <para>
+ The number of pending actions is limited in order to prevent resource exhaustion.
+ For this purpose a high and low watermark has to be passed at construction.
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">high_watermark</phrase></code>
+ sets the maximum of pending tasks. If this limited is reached all threads which
+ submit a tasks will be set to sleep (blocked). <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">low_watermark</phrase></code> sets the threshold when blocked
+ threads get woken up. If high watermark is equal to low watermark everytime
+ a sleeping producer thread will be woken up and puts its task if one worker
+ thread has taken a task from the channel. If low watermark is less than high
+ watermark all sleeping producer threads will be woken up if the amount of pending
+ tasks reaches low watermark.
+ </para>
+ <anchor id="boost_threadpool.channel.unbounded_channel"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.channel.unbounded_channel">unbounded channel</link>
+ </bridgehead>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">SchedulingPolicy</phrase> <phrase role="special">></phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">unbounded_channel</phrase>
+</programlisting>
+ <para>
+ An unlimited number of actions can be queued into this channel. The insertion
+ of actions will never block. If the channel becomes empty worker threads will
+ be set to sleep until new actions are inserted into the channel.
+ </para>
+ </section>
+ <section id="boost_threadpool.scheduling">
+ <title><link linkend="boost_threadpool.scheduling"> Scheduling</link></title>
+ <para>
+ The scheduling policy determines how actions are scheduled inside the <link
+ linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>.
+ </para>
+ <anchor id="boost_threadpool.scheduling.fifo"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.scheduling.fifo">fifo</link>
+ </bridgehead>
+
+<programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">fifo</phrase>
+</programlisting>
+ <para>
+ First inserted pending action get taken first.
+ </para>
+ <anchor id="boost_threadpool.scheduling.lifo"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.scheduling.lifo">lifo</link>
+ </bridgehead>
+
+<programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">lifo</phrase>
+</programlisting>
+ <para>
+ Last inserted pending action get taken first.
+ </para>
+ <anchor id="boost_threadpool.scheduling.priority"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.scheduling.priority">priority</link>
+ </bridgehead>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Ord</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">less</phrase><phrase role="special"><</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="keyword">struct</phrase> <phrase role="identifier">priority</phrase>
+</programlisting>
+ <para>
+ Each pending task is associated with a priority attribute which is used for
+ ordering actions.
+ </para>
+ <anchor id="boost_threadpool.scheduling.smart"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_threadpool.scheduling.smart">smart</link>
+ </bridgehead>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Ord</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Enq</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Deq</phrase> <phrase role="special">></phrase> <phrase role="keyword">struct</phrase> <phrase role="identifier">smart</phrase>
+</programlisting>
+ <para>
+ Each pending actions is associated with an attribute. The scheduler gets an
+ put- and take-policy as template arguments. The corresponding policy get applied
+ for each insertion and removal.
+ </para>
+ <para>
+ <emphasis role="bold">Boost.Threadpool</emphasis> provides <emphasis>boost::tp::replace_oldest</emphasis>
+ as put policy and <emphasis>boost::tp::take_oldest</emphasis> as take policy.
+ Both policies allow the replacement of old actions in the scheduler by new
+ ones.
+ </para>
+
+<programlisting><phrase role="comment">// creates a pool with unbounded channel
+</phrase><phrase role="comment">// tasks are processed depending on the associated attributed
+</phrase><phrase role="comment">// oldest tasks with the same attributed pending in the channel
+</phrase><phrase role="comment">// will be replaced by the new task
+</phrase><phrase role="comment">// this example would execute add( 1, 2) and add( 5, 6)
+</phrase><phrase role="comment">// add( 2, 3) is removed (if pending when add( 5, 6) is submitted)
+</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">smart</phrase><phrase role="special"><</phrase>
+ <phrase role="keyword">int</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">less</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">>,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">replace_oldest</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">take_oldest</phrase>
+ <phrase role="special">></phrase>
+ <phrase role="special">></phrase>
+<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">add_fn</phrase><phrase role="special">,</phrase>
+ <phrase role="number">1</phrase><phrase role="special">,</phrase>
+ <phrase role="number">2</phrase><phrase role="special">),</phrase>
+ <phrase role="number">0</phrase><phrase role="special">);</phrase>
+
+<phrase role="comment">// replaced by later task with same attribute
+</phrase><phrase role="comment">// if still pending in pool
+</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">add_fn</phrase><phrase role="special">,</phrase>
+ <phrase role="number">3</phrase><phrase role="special">,</phrase>
+ <phrase role="number">4</phrase><phrase role="special">),</phrase>
+ <phrase role="number">1</phrase><phrase role="special">);</phrase>
+
+<phrase role="comment">// will replace previous pending action
+</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">add_fn</phrase><phrase role="special">,</phrase>
+ <phrase role="number">5</phrase><phrase role="special">,</phrase>
+ <phrase role="number">6</phrase><phrase role="special">),</phrase>
+ <phrase role="number">1</phrase><phrase role="special">);</phrase>
+</programlisting>
+ </section>
+ <section id="boost_threadpool.forkjoin">
+ <title><link linkend="boost_threadpool.forkjoin"> Fork/Join</link></title>
+ <para>
+ Fork/Join algorithms are recursive divide-and-conquer algorithms which repeatedly
+ splitt sub_actions until they become small enough to solve using simple, short
+ sequential methods, so that they run in parallel on multiple cores.
+ </para>
+ <para>
+ The fork operation creates a new sub_action (which can run in parallel) in
+ the pool. The current actions is not proceeded in the join operation until
+ the forked sub_actions have completed. In the meantime the worker thread executes
+ other actions from its local <link linkend="boost_threadpool.pool.work_stealing"><emphasis>worker
+ queue</emphasis></link>.
+ </para>
+
+<programlisting> <phrase role="comment">// defines the threadpool type
+</phrase> <phrase role="keyword">namespace</phrase> <phrase role="identifier">pt</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">posix_time</phrase><phrase role="special">;</phrase>
+<phrase role="keyword">namespace</phrase> <phrase role="identifier">tp</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">;</phrase>
+
+<phrase role="keyword">typedef</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">fibo</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">private</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
+ <phrase role="special">}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">else</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="special">}</phrase>
+
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">try</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ // defines the threadpool type namespace pt = boost::posix_time; namespace
+ tp = boost::tp;
+ </para>
+
+<programlisting><phrase role="keyword">typedef</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">fibo</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">private</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
+ <phrase role="special">}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">else</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="special">}</phrase>
+
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">try</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ typedef tp::pool< tp::unbounded_channel< tp::fifo > > pool_type;
+ </para>
+
+<programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">fibo</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">private</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
+ <phrase role="special">}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">else</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="special">}</phrase>
+
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">try</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ class fibo { private: int offset_;
+ </para>
+
+<programlisting> <phrase role="keyword">int</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
+ <phrase role="special">}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">else</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="special">}</phrase>
+
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">try</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ int seq<emphasis role="underline">( int n) { if ( n <= 1) return n; else
+ return seq</emphasis>( n - 2) + seq_( n - 1); }
+ </para>
+
+<programlisting> <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">else</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="special">}</phrase>
+
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">try</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ int par<emphasis role="underline">( int n) { if ( n <= offset</emphasis>)
+ return seq_( n); else { tp::task< int > t1( boost::this_task::get_thread_pool<
+ pool<emphasis role="underline">type >().submit( boost::bind( & fibo::par</emphasis>,
+ boost::ref( * this), n - 1) ) ); tp::task< int > t2( boost::this_task::get_thread_pool<
+ pool<emphasis role="underline">type >().submit( boost::bind( & fibo::par</emphasis>,
+ boost::ref( * this), n - 2) ) ); return t1.result().get() + t2.result().get();
+ } }
+ </para>
+
+<programlisting><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{}</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">try</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ public: fibo( int offset) : offset_( offset) {}
+ </para>
+
+<programlisting> <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">try</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ int execute( int n) { int result( par_( n) ); return result; } };
+ </para>
+
+<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">try</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ int main( int argc, char *argv[]) { try { pool_type pool( tp::poolsize( 3)
+ ); fibo fib( 5); std::vector< tp::task< int > > results; results.reserve(
+ 40);
+ </para>
+
+<programlisting> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ pt::ptime start( pt::microsec_clock::universal_time() );
+ </para>
+
+<programlisting> <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ for ( int i = 0; i < 32; ++i) results.push_back( pool.submit( boost::bind(
+ & fibo::execute, boost::ref( fib), i) ) );
+ </para>
+
+<programlisting> <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
+ <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ int k = 0; std::vector< tp::task< int > >::iterator e( results.end()
+ ); for ( std::vector< tp::task< int > >::iterator i( results.begin()
+ ); i != e; ++i) std::cout << "fibonacci " << k++ <<
+ " == " << i->result().get() << std::endl;
+ </para>
+
+<programlisting> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ pt::ptime stop( pt::microsec_clock::universal_time() ); std::cout <<
+ ( stop - start).total_milliseconds() << " milli seconds" <<
+ std::endl;
+ </para>
+
+<programlisting> <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+ <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
+ <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+ <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr <<
+ "exception: " << e.what() << std::endl; } catch ( ...
+ ) { std::cerr << "unhandled" << std::endl; }
+ </para>
+
+<programlisting> <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ <para>
+ return EXIT_FAILURE; }
+ </para>
+ </section>
+ <section id="boost_threadpool.acknowledgement">
+ <title><link linkend="boost_threadpool.acknowledgement"> Acknowledgements</link></title>
+ <para>
+ I'd like to thank Vincente Botet Escriba for his comments on the implementation
+ details of the code and Anthony Williams and Braddock Gaskill for their future
+ libraries.
+ </para>
+ </section>
+ <section id="boost_threadpool.reference">
+ <title><link linkend="boost_threadpool.reference"> Reference</link></title>
+ <section id="boost_threadpool.reference.pool">
+ <title><link linkend="boost_threadpool.reference.pool"> Class template <code><phrase
+ role="identifier">pool</phrase></code></link></title>
+<programlisting> <phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Channel</phrase> <phrase role="special">></phrase>
+ <phrase role="keyword">class</phrase> <phrase role="identifier">pool</phrase>
+ <phrase role="special">:</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">noncopyable</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="special">~</phrase><phrase role="identifier">pool</phrase><phrase role="special">();</phrase>
+
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">();</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">active</phrase><phrase role="special">();</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">idle</phrase><phrase role="special">();</phrase>
+
+ <phrase role="keyword">void</phrase> <phrase role="identifier">shutdown</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">callable</phrase> <phrase role="special">></phrase> <phrase role="identifier">shutdown_now</phrase><phrase role="special">();</phrase>
+
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">terminated</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">terminateing</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">pending</phrase><phrase role="special">();</phrase>
+
+ <phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase> <phrase role="special">></phrase>
+ <phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special"><</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase> <phrase role="special">></phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">act</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">></phrase>
+ <phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special"><</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase> <phrase role="special">></phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">act</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">Attr</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">attr</phrase><phrase role="special">);</phrase>
+ <phrase role="special">};</phrase>
+
+<phrase role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="special">&</phrase> <phrase role="identifier">get_default_pool</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.pool.constructor_unbounded_channel_hw">
+ <title><link linkend="boost_threadpool.reference.pool.constructor_unbounded_channel_hw">
+ Constructor (unbounded channel)</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ Operating system provides functionality for processor pining.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">></phrase></code> instance. For each processor
+ a worker-thread is created and each worker-thread is pined exactly
+ to one processor.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_scanns</phrase></code>, <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Constructor has to be called if a <link linkend="boost_threadpool.channel.unbounded_channel"><emphasis>unbounded
+ channel</emphasis></link> is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.constructor_unbounded_channel">
+ <title><link linkend="boost_threadpool.reference.pool.constructor_unbounded_channel">
+ Constructor (unbounded channel)</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">></phrase></code> instance. Pool contains
+ psize worker-threads.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_scanns</phrase></code>, <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Constructor has to be called if a <link linkend="boost_threadpool.channel.unbounded_channel"><emphasis>unbounded
+ channel</emphasis></link> is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.constructor_bounded_channel_hw">
+ <title><link linkend="boost_threadpool.reference.pool.constructor_bounded_channel_hw">
+ Constructor (bounded channel)</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ Operating system provides functionality for processor pining.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">></phrase></code> instance. For each processor
+ a worker-thread is created and each worker-thread is pined exactly
+ to one processor.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_scanns</phrase></code>, <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>,
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_watermark</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Constructor has to be called if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link> is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.constructor_bounded_channel">
+ <title><link linkend="boost_threadpool.reference.pool.constructor_bounded_channel">
+ Constructor (bounded channel)</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">></phrase></code> instance. Pool contains
+ psize worker-threads.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_scanns</phrase></code>, <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>,
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_watermark</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Constructor has to be called if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link> is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.destructor">
+ <title><link linkend="boost_threadpool.reference.pool.destructor"> Destructor</link></title>
+
+<programlisting><phrase role="special">~</phrase><phrase role="identifier">pool</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Calls <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">pool</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">Channel</phrase> <phrase role="special">>::</phrase><phrase
+ role="identifier">shutdown</phrase><phrase role="special">()</phrase></code>
+ if not yet called.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.size">
+ <title><link linkend="boost_threadpool.reference.pool.size"> Member function
+ <code><phrase role="identifier">size</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns how many worker threads are running in the pool.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.active">
+ <title><link linkend="boost_threadpool.reference.pool.active"> Member function
+ <code><phrase role="identifier">active</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">active</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns how many worker threads are active (executing an action).
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.idle">
+ <title><link linkend="boost_threadpool.reference.pool.idle"> Member function
+ <code><phrase role="identifier">idle</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">idle</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns how many worker threads are idle (not executing an action).
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ The value is the difference of <code><phrase role="identifier">size</phrase><phrase
+ role="special">()</phrase></code> and <code><phrase role="identifier">active</phrase><phrase
+ role="special">()</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.shutdown">
+ <title><link linkend="boost_threadpool.reference.pool.shutdown"> Member function
+ <code><phrase role="identifier">shutdown</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">shutdown</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Changes the pool state to <emphasis>terminating</emphasis>, deactivates
+ the channel and joins all worker threads. The status of the pool is
+ assigned to <emphasis>terminated</emphasis> at the end.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ All pending actions are processed.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.shutdown_now">
+ <title><link linkend="boost_threadpool.reference.pool.shutdown_now"> Member
+ function <code><phrase role="identifier">shutdown_now</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">callable</phrase> <phrase role="special">></phrase> <phrase role="identifier">shutdown_now</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Changes the pool state to <emphasis>terminating</emphasis>, deactivates
+ the channel, send interruption request to all worker threads and joins
+ them. The status of the pool is assigned to <emphasis>terminated</emphasis>
+ at the end.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Pending actions are not processed but returned.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.terminated">
+ <title><link linkend="boost_threadpool.reference.pool.terminated"> Member
+ function <code><phrase role="identifier">terminated</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">terminated</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Queries if the pool is in the terminated state (pool is shutdown).
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.terminateing">
+ <title><link linkend="boost_threadpool.reference.pool.terminateing"> Member
+ function <code><phrase role="identifier">terminateing</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">terminateing</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Queries if the pool is in the terminating state (tries to shutdown
+ the pool).
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.clear">
+ <title><link linkend="boost_threadpool.reference.pool.clear"> Member function
+ <code><phrase role="identifier">clear</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Removes all pending actions from the <link linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.empty">
+ <title><link linkend="boost_threadpool.reference.pool.empty"> Member function
+ <code><phrase role="identifier">empty</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Queries if the <link linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>
+ is empty.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.pending">
+ <title><link linkend="boost_threadpool.reference.pool.pending"> Member function
+ <code><phrase role="identifier">pending</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">pending</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Queries how many actions are pending in the <link linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.get_upper_bound">
+ <title><link linkend="boost_threadpool.reference.pool.get_upper_bound"> Member
+ function <code><phrase role="identifier">upper_bound</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ Channel is of type <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns the upper bound of the <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Can only be used if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link> is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.set_upper_bound">
+ <title><link linkend="boost_threadpool.reference.pool.set_upper_bound"> Member
+ function <code><phrase role="identifier">upper_bound</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase
+ role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase
+ role="special">)</phrase></code></link></title>
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ Channel is of type <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Sets the upper bound of the <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Postconditions:</term>
+ <listitem>
+ <para>
+ <code><phrase role="keyword">this</phrase><phrase role="special">-></phrase><phrase
+ role="identifier">upper_bound</phrase><phrase role="special">()</phrase>
+ <phrase role="special">==</phrase> <phrase role="identifier">hwm</phrase></code>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_watermark</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Can only be used if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link> is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.get_lower_bound">
+ <title><link linkend="boost_threadpool.reference.pool.get_lower_bound"> Member
+ function <code><phrase role="identifier">lower_bound</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ Channel is of type <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns the lower bound of the <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Can only be used if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link> is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.set_lower_bound">
+ <title><link linkend="boost_threadpool.reference.pool.set_lower_bound"> Member
+ function <code><phrase role="identifier">lower_bound</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase
+ role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase
+ role="special">)</phrase></code></link></title>
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ Channel is of type <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Sets the lower bound of the <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Postconditions:</term>
+ <listitem>
+ <para>
+ <code><phrase role="keyword">this</phrase><phrase role="special">-></phrase><phrase
+ role="identifier">lower_bound</phrase><phrase role="special">()</phrase>
+ <phrase role="special">==</phrase> <phrase role="identifier">lwm</phrase></code>.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_watermark</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ Can only be used if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
+ channel</emphasis></link> is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.submit">
+ <title><link linkend="boost_threadpool.reference.pool.submit"> Member function
+ <code><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase
+ role="special">&</phrase> <phrase role="identifier">act</phrase><phrase
+ role="special">)</phrase></code></link></title>
+<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase> <phrase role="special">></phrase>
+<phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special"><</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase> <phrase role="special">></phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">act</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ has_priority< pool >::value == false && ! ( pool.terminating()
+ || pool.terminated() )
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Submits an action to the pool and returns a <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
+ object.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task_rejected</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.submit_attr">
+ <title><link linkend="boost_threadpool.reference.pool.submit_attr"> Member
+ function <code><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase
+ role="special">&</phrase> <phrase role="identifier">act</phrase><phrase
+ role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase
+ role="keyword">const</phrase><phrase role="special">&</phrase> <phrase
+ role="identifier">attr</phrase><phrase role="special">)</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">></phrase>
+<phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special"><</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase> <phrase role="special">></phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">act</phrase><phrase role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">attr</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ has_priority< pool >::value == true && ! ( pool.terminating()
+ || pool.terminated() )
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Submits an action to the pool and returns a <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
+ object. <emphasis role="underline">_Action</emphasis>_ is scheduled
+ by the attribute.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task_rejected</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.pool.get_default_pool">
+ <title><link linkend="boost_threadpool.reference.pool.get_default_pool">
+ Non-member function <code><phrase role="identifier">get_default_pool</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="special">&</phrase> <phrase role="identifier">get_default_pool</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Get access to default thread pool (static).
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.task">
+ <title><link linkend="boost_threadpool.reference.task"> Class template <code><phrase
+ role="identifier">task</phrase></code></link></title>
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase>
+<phrase role="keyword">class</phrase> <phrase role="identifier">task</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
+ <phrase role="identifier">task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">Pool</phrase> <phrase role="special">*</phrase> <phrase role="identifier">pool</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">fut</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">detail</phrase><phrase role="special">::</phrase><phrase role="identifier">interrupter</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">intr</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">(</phrase> <phrase role="identifier">system_time</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Duration</phrase> <phrase role="special">></phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">(</phrase> <phrase role="identifier">Duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">rel_time</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">interrupt_requested</phrase><phrase role="special">();</phrase>
+
+ <phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="identifier">result</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.task.constructor">
+ <title><link linkend="boost_threadpool.reference.task.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
+<phrase role="identifier">task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">Pool</phrase> <phrase role="special">*</phrase> <phrase role="identifier">pool</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">fut</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">detail</phrase><phrase role="special">::</phrase><phrase role="identifier">interrupter</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">intr</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special"><</phrase> <phrase role="identifier">R</phrase>
+ <phrase role="special">></phrase></code> instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ task objects should only be constructed by the pool.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.task.interrupt">
+ <title><link linkend="boost_threadpool.reference.task.interrupt"> Member
+ function <code><phrase role="identifier">interrupt</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">interrupt</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Associated action will be interrupted the next time it enters a <link
+ linkend="boost_threadpool.task.interruption"><emphasis>interruption
+ point</emphasis></link> if interruption is not disabled. The function
+ returns immediatly.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.task.interrupt_and_wait">
+ <title><link linkend="boost_threadpool.reference.task.interrupt_and_wait">
+ Member function <code><phrase role="identifier">interrupt_and_wait</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">();</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">(</phrase> <phrase role="identifier">system_time</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">);</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">DurationTime</phrase> <phrase role="special">></phrase>
+<phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">(</phrase> <phrase role="identifier">DurationTime</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">rel_time</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Associated action will be interrupted the next time it enters one
+ <link linkend="boost_threadpool.task.interruption"><emphasis>interruption
+ point</emphasis></link> if interruption is not disabled. The function
+ waits until the action has terminated or the specified duration td
+ has elapsed.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.task.result">
+ <title><link linkend="boost_threadpool.reference.task.result"> Member function
+ <code><phrase role="identifier">result</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="identifier">result</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns fulfilled value or throws fulfilled exception via a shared_future.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">future</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">broken_promise</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.reschedule_until">
+ <title><link linkend="boost_threadpool.reference.reschedule_until"> Non-member
+ function <code><phrase role="identifier">reschedule_until</phrase></code></link></title>
+
+<programlisting> <phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase>
+<phrase role="keyword">void</phrase> <phrase role="identifier">reschedule_until</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">unique_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="keyword">const</phrase><phrase role="special">&);</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase>
+<phrase role="keyword">void</phrase> <phrase role="identifier">reschedule_until</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="keyword">const</phrase><phrase role="special">&);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Reschedules current task until passed future becomes ready.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ [Throws:
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Nothing.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Note:</term>
+ <listitem>
+ <para>
+ This function resides in namespace <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">this_task</phrase></code>.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.get_thread_pool">
+ <title><link linkend="boost_threadpool.reference.get_thread_pool"> Non-member
+ function <code><phrase role="identifier">get_thread_pool</phrase></code></link></title>
+
+<programlisting> <phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
+<phrase role="identifier">Pool</phrase> <phrase role="special">&</phrase> <phrase role="identifier">get_thread_pool</phrase><phrase role="special">();</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns reference to the thread pool where the current worker thread
+ is running.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ [Throws:
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Nothing.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Note:</term>
+ <listitem>
+ <para>
+ This function resides in namespace <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">this_task</phrase></code>.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.poolsize">
+ <title><link linkend="boost_threadpool.reference.poolsize"> Class <code><phrase
+ role="identifier">poolsize</phrase></code></link></title>
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">poolsize</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.poolsize.constructor">
+ <title><link linkend="boost_threadpool.reference.poolsize.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ value > 0
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">poolsize</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Postconditions:</term>
+ <listitem>
+ <para>
+ operator std::size_t () > 0
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_poolsize</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.poolsize.operator">
+ <title><link linkend="boost_threadpool.reference.poolsize.operator"> Member
+ function <code><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">size_t</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns pool size.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.scanns">
+ <title><link linkend="boost_threadpool.reference.scanns"> Class <code><phrase
+ role="identifier">scanns</phrase></code></link></title>
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">scanns</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">scanns</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.scanns.constructor">
+ <title><link linkend="boost_threadpool.reference.scanns.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ value >= 0
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">scanns</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Postconditions:</term>
+ <listitem>
+ <para>
+ operator std::size_t () >= 0
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_scanns</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.scanns.operator">
+ <title><link linkend="boost_threadpool.reference.scanns.operator"> Member
+ function <code><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">size_t</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns scanns size.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.high_watermark">
+ <title><link linkend="boost_threadpool.reference.high_watermark"> Class <code><phrase
+ role="identifier">high_watermark</phrase></code></link></title>
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">watermark</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">high_watermark</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">high_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.high_watermark.constructor">
+ <title><link linkend="boost_threadpool.reference.high_watermark.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">high_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">high_watermark</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_watermark</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.high_watermark.operator">
+ <title><link linkend="boost_threadpool.reference.high_watermark.operator">
+ Member function <code><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">size_t</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns high watermark.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.low_watermark">
+ <title><link linkend="boost_threadpool.reference.low_watermark"> Class <code><phrase
+ role="identifier">low_watermark</phrase></code></link></title>
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">watermark</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">low_watermark</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">low_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.low_watermark.constructor">
+ <title><link linkend="boost_threadpool.reference.low_watermark.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">low_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">low_watermark</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_watermark</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_threadpool.reference.low_watermark.operator">
+ <title><link linkend="boost_threadpool.reference.low_watermark.operator">
+ Member function <code><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">size_t</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Returns low watermark.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.invalid_poolsize">
+ <title><link linkend="boost_threadpool.reference.invalid_poolsize"> Class
+ <code><phrase role="identifier">invalid_poolsize</phrase></code></link></title>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_poolsize</phrase>
+<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">invalid_poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.invalid_poolsize.constructor">
+ <title><link linkend="boost_threadpool.reference.invalid_poolsize.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="identifier">invalid_poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">invalid_poolsize</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.invalid_scanns">
+ <title><link linkend="boost_threadpool.reference.invalid_scanns"> Class <code><phrase
+ role="identifier">invalid_scanns</phrase></code></link></title>
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_scanns</phrase>
+<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">invalid_scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.invalid_scanns.constructor">
+ <title><link linkend="boost_threadpool.reference.invalid_scanns.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="identifier">invalid_scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">invalid_scanns</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.invalid_timeduration">
+ <title><link linkend="boost_threadpool.reference.invalid_timeduration"> Class
+ <code><phrase role="identifier">invalid_timeduration</phrase></code></link></title>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_timeduration</phrase>
+<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">invalid_timeduration</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.invalid_timeduration.constructor">
+ <title><link linkend="boost_threadpool.reference.invalid_timeduration.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="identifier">invalid_timeduration</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.invalid_watermark">
+ <title><link linkend="boost_threadpool.reference.invalid_watermark"> Class
+ <code><phrase role="identifier">invalid_watermark</phrase></code></link></title>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_watermark</phrase>
+<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">invalid_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.invalid_watermark.constructor">
+ <title><link linkend="boost_threadpool.reference.invalid_watermark.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="identifier">invalid_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">invalid_watermark</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.task_rejected">
+ <title><link linkend="boost_threadpool.reference.task_rejected"> Class <code><phrase
+ role="identifier">task_rejected</phrase></code></link></title>
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">task_rejected</phrase>
+<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">runtime_error</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">task_rejected</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ <section id="boost_threadpool.reference.task_rejected.constructor">
+ <title><link linkend="boost_threadpool.reference.task_rejected.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="identifier">task_rejected</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task_rejected</phrase></code>
+ instance.
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_threadpool.reference.has_priority">
+ <title><link linkend="boost_threadpool.reference.has_priority"> Meta function
+ <code><phrase role="identifier">has_priority</phrase></code></link></title>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">info</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
+<phrase role="keyword">struct</phrase> <phrase role="identifier">has_priority</phrase>
+<phrase role="special">:</phrase>
+<phrase role="keyword">public</phrase> <phrase role="identifier">mpl</phrase><phrase role="special">::</phrase><phrase role="identifier">bool_</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">is_same</phrase><phrase role="special"><</phrase>
+ <phrase role="identifier">detail</phrase><phrase role="special">::</phrase><phrase role="identifier">has_priority</phrase><phrase role="special">,</phrase>
+ <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">::</phrase><phrase role="identifier">scheduler_type</phrase><phrase role="special">::</phrase><phrase role="identifier">priority_tag_type</phrase>
+ <phrase role="special">>::</phrase><phrase role="identifier">value</phrase>
+<phrase role="special">></phrase>
+<phrase role="special">{};</phrase>
+</programlisting>
+ </section>
+ <section id="boost_threadpool.reference.priority_type">
+ <title><link linkend="boost_threadpool.reference.priority_type"> Meta function
+ <code><phrase role="identifier">priority_type</phrase></code></link></title>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">info</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
+<phrase role="keyword">struct</phrase> <phrase role="identifier">priority_type</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">::</phrase><phrase role="identifier">scheduler_type</phrase><phrase role="special">::</phrase><phrase role="identifier">attribute_type</phrase> <phrase role="identifier">type</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </section>
+ </section>
+</library>
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/doc/watermark_ref.qbk 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,75 @@
+[/
+ (C) Copyright 2008 Oliver Kowalke.
+ 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).
+]
+
+[section:high_watermark Class `high_watermark`]
+
+ #include <boost/tp/watermark.hpp>
+
+ class high_watermark
+ {
+ public:
+ explicit high_watermark( std::size_t value);
+
+ operator std::size_t () const;
+ };
+
+[section:constructor Constructor]
+
+ explicit high_watermark( std::size_t value);
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::high_watermark` instance.]]
+[[Throws:] [`boost::tp::invalid_watermark`]]
+]
+[endsect]
+
+[section:operator Member function `operator std::size_t()`]
+
+ operator std::size_t () const;
+
+[variablelist
+[[Effects:] [Returns high watermark.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
+
+
+[section:low_watermark Class `low_watermark`]
+
+ #include <boost/tp/watermark.hpp>
+
+ class low_watermark
+ {
+ public:
+ explicit low_watermark( std::size_t value);
+
+ operator std::size_t () const;
+ };
+
+[section:constructor Constructor]
+
+ explicit low_watermark( std::size_t value);
+
+[variablelist
+[[Effects:] [Constructs a `boost::tp::low_watermark` instance.]]
+[[Throws:] [`boost::tp::invalid_watermark`]]
+]
+[endsect]
+
+[section:operator Member function `operator std::size_t()`]
+
+ operator std::size_t () const;
+
+[variablelist
+[[Effects:] [Returns low watermark.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+[endsect]
\ No newline at end of file
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/Jamfile.v2 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,26 @@
+# Boost.ThreadPool Library Example Jamfile
+
+# Copyright (C) 2008 Oliver Kowalke
+
+# Use, modification and distribution is subject to 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)
+
+# For more information, see http://www.boost.org/
+
+project boost/tp/example
+ : requirements
+ <library>../../thread/build//boost_thread
+ <library>../../system/build//boost_system
+ <threading>multi
+ ;
+
+exe chained_submit : chained_submit.cpp ;
+exe interrupt : interrupt.cpp ;
+exe lazy_submit : lazy_submit.cpp ;
+exe pending : pending.cpp ;
+exe priority : priority.cpp ;
+exe fork_join : fork_join.cpp ;
+exe shutdonw_now : shutdonw_now.cpp ;
+exe smart : smart.cpp ;
+exe submit : submit.cpp ;
\ No newline at end of file
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/fork_join.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,101 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/tp/fifo.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+typedef tp::pool< tp::unbounded_channel< tp::fifo > > pool_type;
+
+class fibo
+{
+private:
+ int offset_;
+
+ int seq_( int n)
+ {
+ if ( n <= 1) return n;
+ else return seq_( n - 2) + seq_( n - 1);
+ }
+
+ int par_( int n)
+ {
+ if ( n <= offset_) return seq_( n);
+ else
+ {
+ tp::task< int > t1(
+ boost::this_task::get_thread_pool< pool_type >().submit(
+ boost::bind(
+ & fibo::par_,
+ boost::ref( * this),
+ n - 1) ) );
+ tp::task< int > t2(
+ boost::this_task::get_thread_pool< pool_type >().submit(
+ boost::bind(
+ & fibo::par_,
+ boost::ref( * this),
+ n - 2) ) );
+ return t1.result().get() + t2.result().get();
+ }
+ }
+
+public:
+ fibo( int offset)
+ : offset_( offset)
+ {}
+
+ int execute( int n)
+ {
+ int result( par_( n) );
+ return result;
+ }
+};
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ pool_type pool( tp::poolsize( 3) );
+ fibo fib( 5);
+ std::vector< tp::task< int > > results;
+ results.reserve( 40);
+
+ pt::ptime start( pt::microsec_clock::universal_time() );
+
+ for ( int i = 0; i < 32; ++i)
+ results.push_back(
+ pool.submit(
+ boost::bind(
+ & fibo::execute,
+ boost::ref( fib),
+ i) ) );
+
+ int k = 0;
+ std::vector< tp::task< int > >::iterator e( results.end() );
+ for (
+ std::vector< tp::task< int > >::iterator i( results.begin() );
+ i != e;
+ ++i)
+ std::cout << "fibonacci " << k++ << " == " << i->result().get() << std::endl;
+
+ pt::ptime stop( pt::microsec_clock::universal_time() );
+ std::cout << ( stop - start).total_milliseconds() << " milli seconds" << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/interrupt.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,69 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/tp/fifo.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+inline
+int fibonacci_fn( int n)
+{
+ if ( n == 0) return 0;
+ if ( n == 1) return 1;
+ int k1( 1), k2( 0);
+ for ( int i( 2); i <= n; ++i)
+ {
+ boost::this_thread::interruption_point();
+ int tmp( k1);
+ k1 = k1 + k2;
+ k2 = tmp;
+ }
+ boost::this_thread::interruption_point();
+ return k1;
+}
+
+inline
+void long_running_fn()
+{ boost::this_thread::sleep( pt::seconds( 1) ); }
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ pool.submit(
+ boost::bind(
+ long_running_fn) );
+ std::cout << "poolsize == " << pool.size() << std::endl;
+ std::cout << "idle threads == " << pool.idle() << std::endl;
+ std::cout << "active threads == " << pool.active() << std::endl;
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ t.interrupt();
+ std::cout << t.result().get() << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( boost::thread_interrupted const& )
+ { std::cerr << "thread_interrupted: task was canceled" << std::endl; }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/parallel_sort.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,273 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-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)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+// Based on the shared.cpp example from the threadalert library of Roland Schwarz
+//////////////////////////////////////////////////////////////////////////////
+
+// requires interthread and range available at boost-sandbox and boost-vault
+
+#include <iostream>
+#include <algorithm>
+
+#include <boost/progress.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/unbounded_channel.hpp>
+#include <boost/tp/fifo.hpp>
+#include <boost/range/algorithm/sort.hpp>
+#include <boost/range/algorithm/inplace_merge.hpp>
+#include <boost/range/sub_range.hpp>
+#include <boost/range/begin.hpp>
+#include <boost/range/end.hpp>
+#include <boost/range/algorithm/equal.hpp>
+#include <boost/range/algorithm/for_each.hpp>
+#include <boost/range/algorithm/transform.hpp>
+#include <boost/range/adaptor/sliced.hpp>
+#include <boost/interthreads/fork.hpp>
+#include <boost/interthreads/algorithm/wait.hpp>
+#include <boost/interthreads/scheduler.hpp>
+#include <boost/array.hpp>
+
+#include <assert.h>
+
+#define BOOST_PARTS 2
+#define NN 10000000
+
+class scoped_timer {
+ boost::posix_time::ptime start_;
+public:
+ scoped_timer()
+ : start_(boost::posix_time::microsec_clock::universal_time())
+ {}
+ ~scoped_timer() {
+ boost::posix_time::ptime stop( boost::posix_time::microsec_clock::universal_time() );
+ std::cout << " " << ( stop - start_).total_milliseconds() << " milli seconds" << std::endl;
+ }
+};
+
+template <typename Range>
+class partition
+{
+public:
+ boost::iterator_range<typename boost::range_iterator<Range>::type> range_;
+ std::size_t parts_;
+ partition(boost::iterator_range<typename boost::range_iterator<Range>::type>& range, std::size_t parts):
+ range_(range),
+ parts_(parts)
+ {}
+ boost::iterator_range<typename boost::range_iterator<Range>::type> operator[](unsigned i) {
+ unsigned size = boost::size(range_);
+ if (i<(parts_-1))
+ return boost::make_sliced_range(range_, i*(size/parts_), ((i+1)*(size/parts_)));
+ else
+ return boost::make_sliced_range(range_, (parts_-1)*(size/parts_), size);
+ }
+};
+
+typedef boost::tp::pool<
+ boost::tp::unbounded_channel< boost::tp::fifo >
+> pool_type;
+
+#ifdef TASK_POOL
+ typedef boost::tp::task< pool_type, void > task_type;
+#else
+ typedef boost::tp::task< void > task_type;
+#endif
+
+
+template <
+ typename DirectSolver,
+ typename Composer,
+ typename AE,
+ typename Range
+>
+ void inplace_solve( AE & ae,
+ boost::iterator_range<typename boost::range_iterator<Range>::type> range,
+ unsigned cutoff );
+
+template <
+ typename DirectSolver,
+ typename Composer,
+ typename AE,
+ typename Range
+>
+ void inplace_solve( AE & ae,
+ boost::iterator_range<typename boost::range_iterator<Range>::type> range,
+ unsigned cutoff )
+ {
+ unsigned size = boost::size(range);
+ //std::cout << "<<par_ " << size;
+ if ( size <= cutoff) DirectSolver()(range);
+ else {
+ partition<Range> parts(range, BOOST_PARTS);
+ std::list<task_type> tasks;
+ #if 0 // this code do not compiles with gcc 3.4.4 cygwin
+ boost::transform(parts, boost::begin(tasks),
+ boost::bind(&AE::submit, boost::ref(ae),
+ //boost::bind(&boost::interthreads::fork<AE>, boost::ref(ae),
+ boost::bind(&inplace_solve<DirectSolver,Composer,AE,Range>, boost::ref(ae),_1,cutoff)));
+ #else
+ for (unsigned i=0;i < BOOST_PARTS-1; ++i) {
+ task_type tmp(ae.submit(
+ boost::bind(
+ &inplace_solve<DirectSolver,Composer,AE,Range>,
+ boost::ref(ae),
+ parts[i],
+ cutoff
+ )));
+ tasks.push_back(tmp);
+ }
+ #endif
+ inplace_solve<DirectSolver,Composer,AE,Range>(ae, parts[BOOST_PARTS-1], cutoff);
+ boost::for_each(tasks, &boost::interthreads::wait_act<task_type>);
+
+ //std::cout << "par_inplace_merge_fct " << size << ">>"<< std::endl;
+ Composer()(range);
+ //std::cout << "par_ " << size << ">>"<< std::endl;
+
+ }
+ }
+
+struct sort_fct {
+ template<class RandomAccessRange>
+ RandomAccessRange& operator()(RandomAccessRange rng) {
+ return boost::sort(rng);
+ }
+};
+
+struct inplace_merge_fct {
+ template<class BidirectionalRange>
+ BidirectionalRange&
+ operator()( BidirectionalRange rng) {
+ return boost::inplace_merge(rng, boost::begin(rng)+(boost::size(rng)/2));
+ }
+};
+template <typename AE, typename Range>
+void parallel_sort(AE& ae, Range& range, unsigned cutoff=10000) {
+ boost::iterator_range<typename boost::range_iterator<Range>::type> rng(range);
+ inplace_solve<sort_fct,inplace_merge_fct,pool_type,Range>( ae, rng, cutoff);
+}
+
+int sorted[NN];
+int values1[NN];
+int values2[NN];
+int values3[NN];
+int values4[NN];
+int values5[NN];
+int values6[NN];
+
+int main() {
+ for (unsigned i=0; i<NN; ++i) sorted[i]=i;
+
+ for (unsigned i=0; i<NN; ++i) values1[i]=NN-i-1;
+ {
+ std::cout << "std::sort: reverse 0.." << NN;
+ scoped_timer t; // start timing
+ std::sort(boost::begin(values1), boost::end(values1));
+ }
+ assert(boost::equal(values1, sorted));
+ {
+ std::cout << "std::sort: 0.." << NN;
+ scoped_timer t; // start timing
+ std::sort(boost::begin(values1), boost::end(values1));
+ }
+
+ for (unsigned i=0; i<NN; ++i) values2[i]=NN-i-1;
+ {
+ std::cout << "boost::sort: reverse 0.."<<NN;
+ scoped_timer t; // start timing
+ boost::sort(values2);
+ }
+ assert(boost::equal(values2, sorted));
+ {
+ std::cout << "boost::sort: 0.."<<NN;
+ scoped_timer t; // start timing
+ boost::sort(values2);
+ }
+
+ // creates a threadpool with two worker-threads
+ pool_type pool( boost::tp::poolsize( 2) );
+
+// // creates a threadpool with as many worker-threads
+// // as CPUs/Cores are online and bind each worker-thread
+// // to a specific CPU/Core
+// // requires BOOST_BIND_WORKER_TO_PROCESSORS to be specified
+// pool_type pool;
+
+ for (unsigned i=0; i<NN; ++i) values5[i]=NN-i-1;
+ {
+ std::cout << "parallel_sort "<<NN/2<<": reverse 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/2);
+ }
+ assert(boost::equal(values5, sorted));
+ {
+ std::cout << "parallel_sort "<<NN/2<<": 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/2);
+ }
+
+ for (unsigned i=0; i<NN; ++i) values5[i]=NN-i-1;
+ {
+ std::cout << "parallel_sort "<<NN/4<<": reverse 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/4);
+ }
+ assert(boost::equal(values5, sorted));
+ {
+ std::cout << "parallel_sort "<<NN/4<<": 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/4);
+ }
+
+ for (unsigned i=0; i<NN; ++i) values5[i]=NN-i-1;
+ {
+ std::cout << "parallel_sort "<<NN/8<<": reverse 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/8);
+ }
+ assert(boost::equal(values5, sorted));
+ {
+ std::cout << "parallel_sort "<<NN/8<<": 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/8);
+ }
+
+ for (unsigned i=0; i<NN; ++i) values5[i]=NN-i-1;
+ {
+ std::cout << "parallel_sort "<<NN/16<<": reverse 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/16);
+ }
+ assert(boost::equal(values5, sorted));
+ {
+ std::cout << "parallel_sort "<<NN/16<<": 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/16);
+ }
+
+ for (unsigned i=0; i<NN; ++i) values5[i]=NN-i-1;
+ {
+ std::cout << "parallel_sort "<<NN/32<<": reverse 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/32);
+ }
+ assert(boost::equal(values5, sorted));
+ {
+ std::cout << "parallel_sort "<<NN/32<<": 0.."<<NN;
+ scoped_timer tmr; // start timing
+ parallel_sort(pool, values5, NN/32);
+ }
+
+
+ std::cout << "shutdown"<< std::endl;
+ pool.shutdown();
+ std::cout << "end"<< std::endl;
+ return 0;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/pending.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,65 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/ref.hpp>
+
+#include "boost/tp/fifo.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+inline
+int fibonacci_fn( int n)
+{
+ if ( n == 0) return 0;
+ if ( n == 1) return 1;
+ int k1( 1), k2( 0);
+ for ( int i( 2); i <= n; ++i)
+ {
+ boost::this_thread::interruption_point();
+ int tmp( k1);
+ k1 = k1 + k2;
+ k2 = tmp;
+ }
+ boost::this_thread::interruption_point();
+ return k1;
+}
+
+inline
+void long_running_fn()
+{ boost::this_thread::sleep( pt::seconds( 1) ); }
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ pool.submit(
+ boost::bind(
+ long_running_fn) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ std::cout << "pending tasks == " << pool.pending() << std::endl;
+ std::cout << t.result().get() << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/priority.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,60 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <string>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/tp/priority.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+inline
+void print_fn( std::string const& msg)
+{ printf("%s", msg.c_str() ); }
+
+inline
+void long_running_fn()
+{ boost::this_thread::sleep( pt::milliseconds( 250) ); }
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool( tp::poolsize( 1) );
+ pool.submit(
+ boost::bind(
+ long_running_fn),
+ 0);
+ pool.submit(
+ boost::bind(
+ print_fn,
+ "This"),
+ 0);
+ pool.submit(
+ boost::bind(
+ print_fn,
+ "a text.\n"),
+ 2);
+ pool.submit(
+ boost::bind(
+ print_fn,
+ " is "),
+ 1);
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/reschedule_until.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,136 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/interprocess/sync/interprocess_semaphore.hpp>
+#include <boost/thread.hpp>
+
+#include "boost/tp/fifo.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+typedef tp::pool< tp::unbounded_channel< tp::fifo > > pool_type;
+
+class fibo
+{
+private:
+ boost::shared_future< void > f_;
+ int offset_;
+
+ class holder
+ {
+ private:
+ boost::shared_future< void > f_;
+
+ public:
+ holder( boost::shared_future< void > const& f)
+ : f_( f)
+ {}
+
+ bool operator()()
+ { return f_.is_ready(); }
+ };
+
+ int seq_( int n)
+ {
+ if ( n <= 1) return n;
+ else return seq_( n - 2) + seq_( n - 1);
+ }
+
+ int par_( int n)
+ {
+ if ( n <= offset_) return seq_( n);
+ else
+ {
+ if ( n == 7)
+ {
+ holder hldr( f_);
+ boost::this_task::reschedule_until( hldr);
+ }
+
+ boost::function< int() > fn1 = boost::bind(
+ & fibo::par_,
+ * this,
+ n - 1);
+ tp::task< int > t1(
+ boost::this_task::get_thread_pool< pool_type >().submit(
+ fn1) );
+ boost::function< int() > fn2 = boost::bind(
+ & fibo::par_,
+ * this,
+ n - 2);
+ tp::task< int > t2(
+ boost::this_task::get_thread_pool< pool_type >().submit(
+ fn2) );
+
+ return t1.result().get() + t2.result().get();
+ }
+ }
+
+public:
+ fibo(
+ boost::shared_future< void > f,
+ int offset)
+ : f_( f), offset_( offset)
+ {}
+
+ int execute( int n)
+ {
+ int result( par_( n) );
+ return result;
+ }
+};
+
+void f() {}
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ pool_type pool( tp::poolsize( 1) );
+ boost::packaged_task< void > tsk( boost::bind( f) );
+ boost::shared_future< void > f( tsk.get_future() );
+ fibo fib( f, 3);
+ std::vector< tp::task< int > > results;
+ results.reserve( 40);
+
+ pt::ptime start( pt::microsec_clock::universal_time() );
+
+ for ( int i = 0; i < 10; ++i)
+ results.push_back(
+ pool.submit(
+ boost::bind(
+ & fibo::execute,
+ boost::ref( fib),
+ i) ) );
+
+ ::sleep( 1);
+ tsk();
+
+ int k = 0;
+ std::vector< tp::task< int > >::iterator e( results.end() );
+ for (
+ std::vector< tp::task< int > >::iterator i( results.begin() );
+ i != e;
+ ++i)
+ std::cout << "fibonacci " << k++ << " == " << i->result().get() << std::endl;
+
+ pt::ptime stop( pt::microsec_clock::universal_time() );
+ std::cout << ( stop - start).total_milliseconds() << " milli seconds" << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/shutdonw_now.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,62 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/ref.hpp>
+
+#include "boost/tp/fifo.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+inline
+int fibonacci_fn( int n)
+{
+ boost::this_thread::sleep( pt::milliseconds( 500) );
+ if ( n == 0) return 0;
+ if ( n == 1) return 1;
+ int k1( 1), k2( 0);
+ for ( int i( 2); i <= n; ++i)
+ {
+ boost::this_thread::interruption_point();
+ int tmp( k1);
+ k1 = k1 + k2;
+ k2 = tmp;
+ }
+ boost::this_thread::interruption_point();
+ return k1;
+}
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ boost::this_thread::sleep( pt::milliseconds( 250) );
+ pool.shutdown_now();
+ std::cout << t.result().get() << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( boost::thread_interrupted const& )
+ { std::cerr << "thread_interrupted: thread was interrupted" << std::endl; }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/smart.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,86 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <string>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/tp/smart.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+inline
+void fibonacci_fn( int n)
+{
+ if ( n == 0)
+ {
+ printf("fibonacci(%d) == 0\n", n);
+ return;
+ }
+ if ( n == 1)
+ {
+ printf("fibonacci(%d) == 1\n", n);
+ return;
+ }
+ int k1( 1), k2( 0);
+ for ( int i( 2); i <= n; ++i)
+ {
+ int tmp( k1);
+ k1 = k1 + k2;
+ k2 = tmp;
+ }
+ printf("fibonacci(%d) == %d\n", n, k1);
+}
+
+inline
+void long_running_fn()
+{ boost::this_thread::sleep( pt::milliseconds( 500) ); }
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ tp::pool<
+ tp::unbounded_channel<
+ tp::smart<
+ int,
+ std::less< int >,
+ tp::replace_oldest,
+ tp::take_oldest
+ >
+ >
+ > pool( tp::poolsize( 1) );
+ pool.submit(
+ boost::bind(
+ long_running_fn),
+ 0);
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 0),
+ 1);
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 1),
+ 2);
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 2);
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/spread_over_hardware.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,102 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/tp/fifo.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+typedef tp::pool< tp::unbounded_channel< tp::fifo > > pool_type;
+
+class fibo
+{
+private:
+ int offset_;
+
+ int seq_( int n)
+ {
+ if ( n <= 1) return n;
+ else return seq_( n - 2) + seq_( n - 1);
+ }
+
+ int par_( int n)
+ {
+ if ( n <= offset_) return seq_( n);
+ else
+ {
+ tp::task< int > t1(
+ boost::this_task::get_thread_pool< pool_type >().submit(
+ boost::bind(
+ & fibo::par_,
+ boost::ref( * this),
+ n - 1) ) );
+ tp::task< int > t2(
+ boost::this_task::get_thread_pool< pool_type >().submit(
+ boost::bind(
+ & fibo::par_,
+ boost::ref( * this),
+ n - 2) ) );
+ return t1.result().get() + t2.result().get();
+ }
+ }
+
+public:
+ fibo( int offset)
+ : offset_( offset)
+ {}
+
+ int execute( int n)
+ {
+ int result( par_( n) );
+ return result;
+ }
+};
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ // ! BOOST_BIND_WORKER_TO_PROCESSORS must be defined !
+ pool_type pool;
+ fibo fib( 5);
+ std::vector< tp::task< int > > results;
+ results.reserve( 40);
+
+ pt::ptime start( pt::microsec_clock::universal_time() );
+
+ for ( int i = 0; i < 32; ++i)
+ results.push_back(
+ pool.submit(
+ boost::bind(
+ & fibo::execute,
+ boost::ref( fib),
+ i) ) );
+
+ int k = 0;
+ std::vector< tp::task< int > >::iterator e( results.end() );
+ for (
+ std::vector< tp::task< int > >::iterator i( results.begin() );
+ i != e;
+ ++i)
+ std::cout << "fibonacci " << k++ << " == " << i->result().get() << std::endl;
+
+ pt::ptime stop( pt::microsec_clock::universal_time() );
+ std::cout << ( stop - start).total_milliseconds() << " milli seconds" << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/examples/submit.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,53 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+
+#include <boost/bind.hpp>
+
+#include "boost/tp/fifo.hpp"
+#include "boost/tp/pool.hpp"
+#include "boost/tp/poolsize.hpp"
+#include "boost/tp/unbounded_channel.hpp"
+
+namespace tp = boost::tp;
+
+inline
+int fibonacci_fn( int n)
+{
+ if ( n == 0) return 0;
+ if ( n == 1) return 1;
+ int k1( 1), k2( 0);
+ for ( int i( 2); i <= n; ++i)
+ {
+ boost::this_thread::interruption_point();
+ int tmp( k1);
+ k1 = k1 + k2;
+ k2 = tmp;
+ }
+ boost::this_thread::interruption_point();
+ return k1;
+}
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ std::cout << t.result().get() << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/src/callable.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,22 @@
+#include "boost/tp/detail/callable.hpp"
+
+namespace boost { namespace tp {
+namespace detail
+{
+callable::callable()
+: impl_()
+{}
+
+void
+callable::operator()()
+{ impl_->run(); }
+
+bool
+callable::empty() const
+{ return ! impl_; }
+
+void
+callable::clear()
+{ impl_.reset(); }
+} } }
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/src/default_pool.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,10 @@
+#include "boost/tp/default_pool.hpp"
+#include <boost/thread.hpp>
+
+namespace boost { namespace tp {
+namespace detail
+{
+default_pool
+static_pool::instance( poolsize( thread::hardware_concurrency() ) );
+}
+} }
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/src/guard.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,19 @@
+#include "boost/tp/detail/guard.hpp"
+
+namespace boost { namespace tp {
+namespace detail
+{
+guard::guard( volatile uint32_t & active_worker)
+: active_worker_( active_worker)
+{
+ BOOST_ASSERT( active_worker_ >= 0);
+ interprocess::detail::atomic_inc32( & active_worker_);
+}
+
+guard::~guard()
+{
+ interprocess::detail::atomic_dec32( & active_worker_);
+ BOOST_ASSERT( active_worker_ >= 0);
+}
+} } }
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/src/interrupter.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,107 @@
+#include "boost/tp/detail/interrupter.hpp"
+
+namespace boost { namespace tp {
+namespace detail
+{
+void
+interrupter::impl::interrupt_()
+{
+ if ( ! interruption_requested_)
+ {
+ interruption_requested_ = true;
+ if ( thrd_) thrd_->interrupt();
+ }
+}
+
+interrupter::impl::impl()
+:
+interruption_requested_( false),
+cond_(),
+mtx_(),
+thrd_()
+{}
+
+void
+interrupter::impl::set( shared_ptr< thread > const& thrd)
+{
+ BOOST_ASSERT( thrd);
+ unique_lock< mutex > lk( mtx_);
+ thrd_ = thrd;
+ BOOST_ASSERT( thrd_);
+ if ( interruption_requested_) thrd_->interrupt();
+}
+
+void
+interrupter::impl::reset()
+{
+ unique_lock< mutex > lk( mtx_);
+ thrd_.reset();
+ BOOST_ASSERT( ! thrd_);
+ try
+ { this_thread::interruption_point(); }
+ catch ( thread_interrupted const&)
+ {}
+ BOOST_ASSERT( ! this_thread::interruption_requested() );
+ cond_.notify_all();
+}
+
+void
+interrupter::impl::interrupt()
+{
+ unique_lock< mutex > lk( mtx_);
+ interrupt_();
+}
+
+void
+interrupter::impl::interrupt_and_wait()
+{
+ unique_lock< mutex > lk( mtx_);
+ interrupt_();
+ cond_.wait( lk);
+}
+
+void
+interrupter::impl::interrupt_and_wait( system_time const& abs_time)
+{
+ unique_lock< mutex > lk( mtx_);
+ interrupt_();
+ cond_.timed_wait( lk, abs_time);
+}
+
+bool
+interrupter::impl::interruption_requested()
+{
+ unique_lock< mutex > lk( mtx_);
+ return interruption_requested_;
+}
+
+interrupter::interrupter()
+: impl_( new impl() )
+{}
+
+void
+interrupter::set( shared_ptr< thread > const& thrd)
+{ impl_->set( thrd); }
+
+void
+interrupter::reset()
+{ impl_->reset(); }
+
+void
+interrupter::interrupt()
+{ impl_->interrupt(); }
+
+void
+interrupter::interrupt_and_wait()
+{ impl_->interrupt_and_wait(); }
+
+void
+interrupter::interrupt_and_wait( system_time const& abs_time)
+{ impl_->interrupt_and_wait( abs_time); }
+
+bool
+interrupter::interruption_requested()
+{ return impl_->interruption_requested(); }
+}
+} }
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/src/poolsize.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,12 @@
+#include "boost/tp/poolsize.hpp"
+
+namespace boost { namespace tp
+{
+poolsize::poolsize( std::size_t value)
+: value_( value)
+{ if ( value <= 0) throw invalid_poolsize("core poolsize must be greater than zero"); }
+
+poolsize::operator std::size_t () const
+{ return value_; }
+} }
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/src/scanns.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,12 @@
+#include "boost/tp/scanns.hpp"
+
+namespace boost { namespace tp
+{
+scanns::scanns( std::size_t value)
+: value_( value)
+{ if ( value < 0) throw invalid_scanns("scanns must be greater than or equal to zero"); }
+
+scanns::operator std::size_t () const
+{ return value_; }
+} }
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/src/watermark.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,24 @@
+#include "boost/tp/watermark.hpp"
+
+namespace boost { namespace tp
+{
+high_watermark::high_watermark( std::size_t value)
+: value_( value)
+{
+ if ( value <= 0)
+ throw invalid_watermark("high watermark must be greater than zero");
+}
+
+high_watermark::operator std::size_t () const
+{ return value_; }
+
+low_watermark::low_watermark( std::size_t value)
+: value_( value)
+{
+ if ( value < 0)
+ throw invalid_watermark("low watermark must be greater than or equal to zero");
+}
+
+low_watermark::operator std::size_t () const
+{ return value_; }
+} }
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/src/worker.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,189 @@
+#include "boost/tp/detail/worker.hpp"
+
+namespace boost {
+namespace tp {
+namespace detail
+{
+thread_specific_ptr< worker > worker::tss_;
+
+worker::impl::impl( function< void() > const& fn)
+:
+thrd_( new thread( fn) ),
+wsq_(),
+shtdwn_sem_( 0),
+shtdwn_now_sem_( 0),
+shtdwn_( false),
+scns_( 0)
+{ BOOST_ASSERT( ! fn.empty() ); }
+
+const shared_ptr< thread >
+worker::impl::thrd() const
+{ return thrd_; }
+
+const thread::id
+worker::impl::get_id() const
+{ return thrd_->get_id(); }
+
+void
+worker::impl::join() const
+{ thrd_->join(); }
+
+void
+worker::impl::interrupt() const
+{ thrd_->interrupt(); }
+
+void
+worker::impl::put(
+ callable const& ca,
+ interrupter const& intr)
+{
+ BOOST_ASSERT( ! ca.empty() );
+ wsq_.put( std::make_pair( ca, intr) );
+}
+
+bool
+worker::impl::try_take(
+ callable & ca,
+ interrupter & intr)
+{
+ item itm;
+ bool result( wsq_.try_take( itm) );
+ if ( result)
+ {
+ ca = itm.first;
+ intr = itm.second;
+ }
+ return result;
+}
+
+bool
+worker::impl::try_steal(
+ callable & ca,
+ interrupter & intr)
+{
+ item itm;
+ bool result( wsq_.try_steal( itm) );
+ if ( result)
+ {
+ ca = itm.first;
+ intr = itm.second;
+ }
+ return result;
+}
+
+bool
+worker::impl::empty()
+{ return wsq_.empty(); }
+
+void
+worker::impl::signal_shutdown()
+{ shtdwn_sem_.post(); }
+
+void
+worker::impl::signal_shutdown_now()
+{ shtdwn_now_sem_.post(); }
+
+bool
+worker::impl::shutdown()
+{
+ if ( ! shtdwn_)
+ shtdwn_ = shtdwn_sem_.try_wait();
+ return shtdwn_;
+}
+
+bool
+worker::impl::shutdown_now()
+{ return shtdwn_now_sem_.try_wait(); }
+
+std::size_t
+worker::impl::scanns() const
+{ return scns_; }
+
+void
+worker::impl::increment_scanns()
+{ ++scns_; }
+
+void
+worker::impl::reset_scanns()
+{ scns_ = 0; }
+
+const shared_ptr< thread >
+worker::thrd() const
+{ return impl_->thrd(); }
+
+const thread::id
+worker::get_id() const
+{ return impl_->get_id(); }
+
+void
+worker::join() const
+{ impl_->join(); }
+
+void
+worker::interrupt() const
+{ impl_->interrupt(); }
+
+void
+worker::put(
+ callable const& ca,
+ interrupter const& intr)
+{ impl_->put( ca, intr); }
+
+bool
+worker::try_take(
+ callable & ca,
+ interrupter & intr)
+{ return impl_->try_take( ca, intr); }
+
+bool
+worker::try_steal(
+ callable & ca,
+ interrupter & intr)
+{ return impl_->try_steal( ca, intr); }
+
+bool
+worker::empty() const
+{ return impl_->empty(); }
+
+void
+worker::signal_shutdown()
+{ impl_->signal_shutdown(); }
+
+void
+worker::signal_shutdown_now()
+{ impl_->signal_shutdown_now(); }
+
+bool
+worker::shutdown()
+{ return impl_->shutdown(); }
+
+bool
+worker::shutdown_now()
+{ return impl_->shutdown_now(); }
+
+std::size_t
+worker::scanns() const
+{ return impl_->scanns(); }
+
+void
+worker::increment_scanns()
+{ impl_->increment_scanns(); }
+
+void
+worker::reset_scanns()
+{ impl_->reset_scanns(); }
+
+void
+worker::reschedule_until( function< bool() > const& pred)
+{ return impl_->reschedule_until( pred); }
+
+worker *
+worker::tss_get()
+{ return worker::tss_.get(); }
+
+void
+worker::tss_reset( worker * w)
+{ worker::tss_.reset( w); }
+
+} } }
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/Jamfile.v2 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,41 @@
+# Boost.ThreadPool Library Test Jamfile
+
+# Copyright (C) 2008 Oliver Kowalke
+
+# Use, modification and distribution is subject to 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)
+
+# bring in rules for testing
+import testing ;
+
+project
+ : requirements
+ <library>/boost/test//boost_unit_test_framework
+ <library>/boost/thread//boost_thread
+ <library>/boost/system//boost_system
+ #<library>/boost/exception//boost_exception
+ <library>../../tp/build//boost_threadpool
+ <link>static
+ <threading>multi
+ <include>../../..
+ <include>$(BOOST_ROOT)
+ ;
+
+rule tp-test ( source )
+{
+ return
+ [ run $(source).cpp ]
+ ;
+}
+
+test-suite thread_pool :
+ [ tp-test test_bounded_queue_fifo ]
+ [ tp-test test_bounded_queue_lifo ]
+ [ tp-test test_bounded_queue_priority ]
+ [ tp-test test_bounded_queue_smart ]
+ [ tp-test test_unbounded_queue_fifo ]
+ [ tp-test test_unbounded_queue_lifo ]
+ [ tp-test test_unbounded_queue_priority ]
+ [ tp-test test_unbounded_queue_smart ]
+ ;
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_bounded_queue_fifo.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,304 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/future.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/fifo.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/task.hpp>
+#include <boost/tp/watermark.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+class fixed_bounded_channel_fifo
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool(
+ tp::poolsize( 3),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn) ) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ }
+ catch ( tp::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 1),
+ tp::low_watermark( 1) );
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, pt::time_duration const&) ) delay_fn,
+ fn,
+ pt::millisec( 500) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tp::task< int > t2( pool.submit( fn) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tp::task< int > t3( pool.submit( fn) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ BOOST_CHECK_EQUAL( t1.result().get(), 55);
+ BOOST_CHECK_EQUAL( t2.result().get(), 55);
+ BOOST_CHECK_EQUAL( t3.result().get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check fifo scheduling
+ void test_case_8()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 55);
+ BOOST_CHECK_EQUAL( buffer[1], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check cancelation
+ void test_case_9()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::fifo >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) ) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ t.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: fixed bounded_channel< fifo > pool test suite") );
+
+ boost::shared_ptr< fixed_bounded_channel_fifo > instance( new fixed_bounded_channel_fifo() );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_fifo::test_case_9, instance) );
+
+ return test;
+}
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_bounded_queue_lifo.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,304 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/future.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/lifo.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/task.hpp>
+#include <boost/tp/watermark.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+class fixed_bounded_channel_lifo
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool(
+ tp::poolsize( 3),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn) ) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ }
+ catch ( tp::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 1),
+ tp::low_watermark( 1) );
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, pt::time_duration const&) ) delay_fn,
+ fn,
+ pt::millisec( 500) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tp::task< int > t2( pool.submit( fn) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tp::task< int > t3( pool.submit( fn) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ BOOST_CHECK_EQUAL( t1.result().get(), 55);
+ BOOST_CHECK_EQUAL( t2.result().get(), 55);
+ BOOST_CHECK_EQUAL( t3.result().get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check lifo scheduling
+ void test_case_8()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check cancelation
+ void test_case_9()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::lifo >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) ) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ t.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: fixed bounded_channel< lifo > pool test suite") );
+
+ boost::shared_ptr< fixed_bounded_channel_lifo > instance( new fixed_bounded_channel_lifo() );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_lifo::test_case_9, instance) );
+
+ return test;
+}
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_bounded_queue_priority.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,318 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/future.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/priority.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/task.hpp>
+#include <boost/tp/watermark.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+class fixed_bounded_channel_priority
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool(
+ tp::poolsize( 3),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0) );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn),
+ 0) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0);
+ }
+ catch ( tp::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 1),
+ tp::low_watermark( 1) );
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, pt::time_duration const&) ) delay_fn,
+ fn,
+ pt::millisec( 500) ),
+ 0) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 0) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tp::task< int > t2( pool.submit( fn, 0) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tp::task< int > t3( pool.submit( fn, 0) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ BOOST_CHECK_EQUAL( t1.result().get(), 55);
+ BOOST_CHECK_EQUAL( t2.result().get(), 55);
+ BOOST_CHECK_EQUAL( t3.result().get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check priority scheduling
+ void test_case_8()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 1);
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 0);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check cancelation
+ void test_case_9()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::priority< int > >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 0) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 0);
+ t.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: fixed bounded_channel< priority< int > > pool test suite") );
+
+ boost::shared_ptr< fixed_bounded_channel_priority > instance( new fixed_bounded_channel_priority() );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_priority::test_case_9, instance) );
+
+ return test;
+}
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_bounded_queue_smart.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,324 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/future.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/smart.hpp>
+#include <boost/tp/task.hpp>
+#include <boost/tp/watermark.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+class fixed_bounded_channel_smart
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool(
+ tp::poolsize( 3),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0) );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn),
+ 0) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0);
+ }
+ catch ( tp::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 1),
+ tp::low_watermark( 1) );
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, pt::time_duration const&) ) delay_fn,
+ fn,
+ pt::millisec( 500) ),
+ 0) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 0) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tp::task< int > t2( pool.submit( fn, 1) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tp::task< int > t3( pool.submit( fn, 2) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ BOOST_CHECK_EQUAL( t1.result().get(), 55);
+ BOOST_CHECK_EQUAL( t2.result().get(), 55);
+ BOOST_CHECK_EQUAL( t3.result().get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check smart scheduling
+ void test_case_8()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 2);
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 1);
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 1),
+ 2);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 1);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check cancelation
+ void test_case_9()
+ {
+ typedef tp::pool<
+ tp::bounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool_type;
+ pool_type pool(
+ tp::poolsize( 1),
+ tp::high_watermark( 10),
+ tp::low_watermark( 10) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 2) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 1);
+ t.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: fixed bounded_channel< smart< int > > pool test suite") );
+
+ boost::shared_ptr< fixed_bounded_channel_smart > instance( new fixed_bounded_channel_smart() );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_bounded_channel_smart::test_case_9, instance) );
+
+ return test;
+}
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_functions.hpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,94 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TP_TEST_FUNCTIONS_H
+#define BOOST_TP_TEST_FUNCTIONS_H
+
+#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/future.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/auto_unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/fifo.hpp>
+#include <boost/tp/lifo.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/priority.hpp>
+#include <boost/tp/smart.hpp>
+#include <boost/tp/task.hpp>
+#include <boost/tp/unbounded_channel.hpp>
+#include <boost/tp/watermark.hpp>
+
+#include <boost/tp/detail/interrupter.hpp>
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+inline
+int add_fn(
+ int a,
+ int b)
+{
+ boost::this_thread::interruption_point();
+ return a + b;
+}
+
+template< typename Fn >
+typename boost::result_of< Fn() >::type barrier_fn(
+ Fn const& fn,
+ boost::barrier & b)
+{
+ b.wait();
+ return fn();
+}
+
+template< typename Fn >
+typename boost::result_of< Fn() >::type delay_fn(
+ Fn const& fn,
+ pt::time_duration const& td)
+{
+ boost::this_thread::sleep( td);
+ return fn();
+}
+
+inline
+int fibonacci_fn( int n)
+{
+ if ( n < 2) return n;
+ int k1( 1), k2( 0);
+ for ( int i( 2); i <= n; ++i)
+ {
+ boost::this_thread::interruption_point();
+ int tmp( k1);
+ k1 = k1 + k2;
+ k2 = tmp;
+ }
+ boost::this_thread::interruption_point();
+ return k1;
+}
+
+inline
+void buffer_fibonacci_fn(
+ std::vector< int > & buffer,
+ int n)
+{ buffer.push_back( fibonacci_fn( n) ); }
+
+inline
+void throwing_fn()
+{ throw std::runtime_error("exception thrown"); }
+
+#endif // BOOST_TP_TEST_FUNCTIONS_H
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_unbounded_queue_fifo.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,275 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/future.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/fifo.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+class fixed_unbounded_channel_fifo
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 3) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn) ) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ }
+ catch ( tp::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool( tp::poolsize( 1) );
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, pt::time_duration const&) ) delay_fn,
+ fn,
+ pt::millisec( 500) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tp::task< int > t2( pool.submit( fn) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tp::task< int > t3( pool.submit( fn) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ BOOST_CHECK_EQUAL( t1.result().get(), 55);
+ BOOST_CHECK_EQUAL( t2.result().get(), 55);
+ BOOST_CHECK_EQUAL( t3.result().get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check fifo scheduling
+ void test_case_8()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 55);
+ BOOST_CHECK_EQUAL( buffer[1], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check interruptation
+ void test_case_9()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::fifo >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) ) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ t.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: fixed unbounded_channel< fifo > pool test suite") );
+
+ boost::shared_ptr< fixed_unbounded_channel_fifo > instance( new fixed_unbounded_channel_fifo() );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_fifo::test_case_9, instance) );
+
+ return test;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_unbounded_queue_lifo.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,275 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/future.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/lifo.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+class fixed_unbounded_channel_lifo
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool( tp::poolsize( 3) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool( tp::poolsize( 1) );
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn) ) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool( tp::poolsize( 1) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ }
+ catch ( tp::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool( tp::poolsize( 1) );
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, pt::time_duration const&) ) delay_fn,
+ fn,
+ pt::millisec( 500) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) ) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tp::task< int > t2( pool.submit( fn) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tp::task< int > t3( pool.submit( fn) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ BOOST_CHECK_EQUAL( t1.result().get(), 55);
+ BOOST_CHECK_EQUAL( t2.result().get(), 55);
+ BOOST_CHECK_EQUAL( t3.result().get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check lifo scheduling
+ void test_case_8()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check interruptation
+ void test_case_9()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::lifo >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) ) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ t.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: fixed unbounded_channel< lifo > pool test suite") );
+
+ boost::shared_ptr< fixed_unbounded_channel_lifo > instance( new fixed_unbounded_channel_lifo() );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_lifo::test_case_9, instance) );
+
+ return test;
+}
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_unbounded_queue_priority.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,290 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/future.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/priority.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+class fixed_unbounded_channel_priority
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool( tp::poolsize( 3) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0) );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool( tp::poolsize( 1) );
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn),
+ 0) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool( tp::poolsize( 1) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0);
+ }
+ catch ( tp::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool( tp::poolsize( 1) );
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, pt::time_duration const&) ) delay_fn,
+ fn,
+ pt::millisec( 500) ),
+ 0) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 0) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tp::task< int > t2( pool.submit( fn, 0) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tp::task< int > t3( pool.submit( fn, 0) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ BOOST_CHECK_EQUAL( t1.result().get(), 55);
+ BOOST_CHECK_EQUAL( t2.result().get(), 55);
+ BOOST_CHECK_EQUAL( t3.result().get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check priority scheduling
+ void test_case_8()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 1);
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 0);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check interruptation
+ void test_case_9()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::priority< int > >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 0) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 0);
+ t.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: fixed unbounded_channel< priority< int > > pool test suite") );
+
+ boost::shared_ptr< fixed_unbounded_channel_priority > instance( new fixed_unbounded_channel_priority() );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_priority::test_case_9, instance) );
+
+ return test;
+}
+
==============================================================================
--- (empty file)
+++ sandbox/async/libs/tp/test/test_unbounded_queue_smart.cpp 2009-10-13 03:35:29 EDT (Tue, 13 Oct 2009)
@@ -0,0 +1,296 @@
+// Copyright (c) 2008 Oliver Kowalke. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/future.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/tp/bounded_channel.hpp>
+#include <boost/tp/exceptions.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/tp/poolsize.hpp>
+#include <boost/tp/smart.hpp>
+#include <boost/tp/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tp = boost::tp;
+
+class fixed_unbounded_channel_smart
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool( tp::poolsize( 3) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0) );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool( tp::poolsize( 1) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( t.result().get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool( tp::poolsize( 1) );
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ throwing_fn),
+ 0) );
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool( tp::poolsize( 1) );
+ pool.shutdown();
+ BOOST_CHECK( pool.terminated() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ boost::bind(
+ fibonacci_fn,
+ 10),
+ 0);
+ }
+ catch ( tp::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with boost::thread_interrupted exception
+ void test_case_6()
+ {
+ tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool( tp::poolsize( 1) );
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, pt::time_duration const&) ) delay_fn,
+ fn,
+ pt::millisec( 500) ),
+ 0) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 0) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.terminated() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ tp::task< int > t1(
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0) );
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tp::task< int > t2( pool.submit( fn, 1) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tp::task< int > t3( pool.submit( fn, 2) );
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ BOOST_CHECK_EQUAL( t1.result().get(), 55);
+ BOOST_CHECK_EQUAL( t2.result().get(), 55);
+ BOOST_CHECK_EQUAL( t3.result().get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check smart scheduling
+ void test_case_8()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 2);
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 1);
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 1),
+ 2);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 1);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check interruptation
+ void test_case_9()
+ {
+ typedef tp::pool<
+ tp::unbounded_channel< tp::smart< int, std::less< int >, tp::replace_oldest, tp::take_oldest > >
+ > pool_type;
+ pool_type pool( tp::poolsize( 1) );
+ boost::barrier b( 2);
+ boost::function< int() > fn(
+ boost::bind(
+ fibonacci_fn,
+ 10) );
+ pool.submit(
+ boost::bind(
+ ( int ( *)( boost::function< int() > const&, boost::barrier &) ) barrier_fn,
+ fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ tp::task< void > t(
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 2) );
+ pool.submit(
+ boost::bind(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 1);
+ t.interrupt();
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 1) );
+ bool thrown( false);
+ try
+ { t.result().get(); }
+ catch ( boost::thread_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: fixed unbounded_channel< smart< int > > pool test suite") );
+
+ boost::shared_ptr< fixed_unbounded_channel_smart > instance( new fixed_unbounded_channel_smart() );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & fixed_unbounded_channel_smart::test_case_9, instance) );
+
+ return test;
+}
+