Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52446 - in sandbox/task/libs/task: doc examples test
From: oliver.kowalke_at_[hidden]
Date: 2009-04-17 12:19:13


Author: olli
Date: 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
New Revision: 52446
URL: http://svn.boost.org/trac/boost/changeset/52446

Log:
* moved sources from threadpool

Added:
   sandbox/task/libs/task/doc/
   sandbox/task/libs/task/doc/Jamfile.v2 (contents, props changed)
   sandbox/task/libs/task/doc/acknowledgement.qbk (contents, props changed)
   sandbox/task/libs/task/doc/channel.qbk (contents, props changed)
   sandbox/task/libs/task/doc/exceptions_ref.qbk (contents, props changed)
   sandbox/task/libs/task/doc/forkjoin.qbk (contents, props changed)
   sandbox/task/libs/task/doc/introduction.qbk (contents, props changed)
   sandbox/task/libs/task/doc/meta_ref.qbk (contents, props changed)
   sandbox/task/libs/task/doc/pool.qbk (contents, props changed)
   sandbox/task/libs/task/doc/pool_ref.qbk (contents, props changed)
   sandbox/task/libs/task/doc/poolsize_ref.qbk (contents, props changed)
   sandbox/task/libs/task/doc/reference.qbk (contents, props changed)
   sandbox/task/libs/task/doc/scanns_ref.qbk (contents, props changed)
   sandbox/task/libs/task/doc/scheduling.qbk (contents, props changed)
   sandbox/task/libs/task/doc/stacksize_ref.qbk (contents, props changed)
   sandbox/task/libs/task/doc/task.qbk (contents, props changed)
   sandbox/task/libs/task/doc/task_ref.qbk (contents, props changed)
   sandbox/task/libs/task/doc/this_task.qbk (contents, props changed)
   sandbox/task/libs/task/doc/this_task_ref.qbk (contents, props changed)
   sandbox/task/libs/task/doc/threadpool.qbk (contents, props changed)
   sandbox/task/libs/task/doc/threadpool.xml (contents, props changed)
   sandbox/task/libs/task/doc/watermark_ref.qbk (contents, props changed)
   sandbox/task/libs/task/examples/
   sandbox/task/libs/task/examples/Jamfile.v2 (contents, props changed)
   sandbox/task/libs/task/examples/bind_to_processors.cpp (contents, props changed)
   sandbox/task/libs/task/examples/delay.cpp (contents, props changed)
   sandbox/task/libs/task/examples/fork_join.cpp (contents, props changed)
   sandbox/task/libs/task/examples/interrupt.cpp (contents, props changed)
   sandbox/task/libs/task/examples/pending.cpp (contents, props changed)
   sandbox/task/libs/task/examples/priority.cpp (contents, props changed)
   sandbox/task/libs/task/examples/reschedule_until.cpp (contents, props changed)
   sandbox/task/libs/task/examples/shutdonw_now.cpp (contents, props changed)
   sandbox/task/libs/task/examples/smart.cpp (contents, props changed)
   sandbox/task/libs/task/examples/submit.cpp (contents, props changed)
   sandbox/task/libs/task/examples/yield.cpp (contents, props changed)
   sandbox/task/libs/task/test/
   sandbox/task/libs/task/test/Jamfile.v2 (contents, props changed)
   sandbox/task/libs/task/test/test_functions.hpp (contents, props changed)
   sandbox/task/libs/task/test/test_launch.cpp (contents, props changed)
   sandbox/task/libs/task/test/test_pool_bounded_channel.cpp (contents, props changed)
   sandbox/task/libs/task/test/test_pool_unbounded_channel.cpp (contents, props changed)

Added: sandbox/task/libs/task/doc/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/Jamfile.v2 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/acknowledgement.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/acknowledgement.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/channel.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/channel.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,38 @@
+[/
+ (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 scheduling policy.
+If the channel becomes empty all __worker_threads__ are set to sleep until a new __action__ is put in.
+
+[/
+[heading lockfree channel]
+
+ class lockfree_channel
+
+Uses internaly a lockfree algorithm in order to get a fifo queue.
+]
+
+[heading bounded channel]
+
+ template< typename SchedulingPolicy > class bounded_channel
+
+Contains a single lock in order to synchronize access to the queue. 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
+
+Contains a single lock in order to synchronize access to the queue. 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/task/libs/task/doc/exceptions_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/exceptions_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/forkjoin.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/forkjoin.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/introduction.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/introduction.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/meta_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/meta_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/pool.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/pool.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,123 @@
+[/
+ (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 pool is set closed and all __worker_threads__ are joined until all pending __actions__ are processed. No futher __actions__ can be submitted by application threads.
+
+[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()` closes the pool, interrupts and then joins all __worker_threads__. 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 Launch in pool]
+The free function `boost::tp::launch_in_pool( Act const& act)` submits the __action__ to the default pool and returns a task object.
+
+[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/task/libs/task/doc/pool_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/pool_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,353 @@
+[/
+ (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 closed();
+ 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();
+
+ template< typename Act >
+ task< R > launch_in_pool( Act const& act);
+
+[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:] [Deactivates the channel and joins all worker threads. The pool is closed.]]
+[[Throws:] [Nothing]]
+[[Notes:] [All pending __actions__ are processed.]]
+]
+[endsect]
+
+
+[section:shutdown_now Member function `shutdown_now()`]
+
+ const std::vector< callable > shutdown_now();
+
+[variablelist
+[[Effects:] [Deactivates the channel, send interruption request to all worker threads and joins them. The pool is closed.]]
+[[Throws:] [Nothing]]
+[[Notes:] [Pending __actions__ are not processed but returned.]]
+]
+[endsect]
+
+
+[section:losed Member function `closed()`]
+
+ bool closed();
+
+[variablelist
+[[Effects:] [Queries if the pool is closed (pool is shutdown).]]
+[[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 && ! closed()]]
+[[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 && ! closed()]]
+[[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]
+
+
+[section:launch_in_pool Non-member function `launch_in_pool( Act const& act)`]
+
+ template< typename Act >
+ task< R > launch_in_pool( Act const& act);
+
+[variablelist
+[[Preconditions:] [has_priority< pool >::value == false && ! closed()]]
+[[Effects:] [Submits an __action__ to the default pool and returns a __task__ object.]]
+[[Throws:] [`boost::tp::task_rejected`]]
+]
+[endsect]
+
+
+[endsect]

Added: sandbox/task/libs/task/doc/poolsize_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/poolsize_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/reference.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/reference.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/scanns_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/scanns_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/scheduling.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/scheduling.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/stacksize_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/stacksize_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/task.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/task.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,123 @@
+[/
+ (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.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.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.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::exception`
+* `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.get() << std::endl; // will rethrow an std::runtime_error
+
+[endsect]

Added: sandbox/task/libs/task/doc/task_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/task_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,162 @@
+[/
+ (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,
+ 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();
+
+ R get() const;
+
+ bool is_ready() const;
+ bool has_value() const;
+ bool has_exception() const;
+
+ void wait() const;
+ template< typename Duration >
+ bool timed_wait( Duration const& rel_time) const;
+ bool timed_wait_until( system_time const& abs_time) const;
+ };
+
+[section:constructor Constructor]
+
+ template< typename Pool >
+ task(
+ Pool * pool,
+ 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:get Member function `get()`]
+
+ R get() const;
+
+[variablelist
+[[Effects:] [Returns fulfilled value or throws fulfilled exception.]]
+[[Throws:] [`boost::future::broken_promise`]]
+]
+[endsect]
+
+
+[section:is_read Member function `is_ready()`]
+
+ bool is_ready() const;
+
+[variablelist
+[[Effects:] [Queries if the __action__ has been fulfilled.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:has_value Member function `has_value()`]
+
+ bool has_value() const;
+
+[variablelist
+[[Effects:] [Queries if the __action__ has been fulfilled (is ready) and has a value.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:has_exception Member function `has_exception()`]
+
+ bool has_exception() const;
+
+[variablelist
+[[Effects:] [Queries if the __action__ has been fulfilled (is ready) and has an exception.]]
+[[Throws:] [Nothing]]
+]
+[endsect]
+
+
+[section:wait Member function `wait()`]
+
+ void wait() const;
+
+[variablelist
+[[Effects:] [Waits until the result is ready.]]
+[[Throws:] [Throws thread_interrupted if the result is not ready at the point of the call, and the current thread is interrupted.]]
+]
+[endsect]
+
+
+[section:timed_wait Member function `timed_wait()`]
+
+ template< typename Duration >
+ bool timed_wait( Duration const& wait_duration);
+
+[variablelist
+[[Effects:] [Waits until the result is ready, or returns false if the time specified by wait_duration has elapsed.]]
+[[Throws:] [Throws thread_interrupted if the result is not ready at the point of the call, and the current thread is interrupted.]]
+]
+[endsect]
+
+
+[section:timed_wait_until Member function `timed_wait_until()`]
+
+ bool timed_wait_until( system_time const& wait_timeout);
+
+[variablelist
+[[Effects:] [Waits until the result is ready, or returns false if the time point specified by wait_timeout has passed.]]
+[[Throws:] [Throws thread_interrupted if the result is not ready at the point of the call, and the current thread is interrupted.]]
+]
+[endsect]
+
+
+[endsect]

Added: sandbox/task/libs/task/doc/this_task.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/this_task.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/this_task_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/this_task_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/threadpool.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/threadpool.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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/task/libs/task/doc/threadpool.xml
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/threadpool.xml 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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">&lt;</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">&gt;</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">&lt;</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">&lt;</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">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;</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">&lt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">Channel</phrase> <phrase
+ role="special">&gt;::</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">&lt;</phrase> <phrase
+ role="identifier">Channel</phrase> <phrase role="special">&gt;::</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">&lt;</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">&lt;</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">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</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">&lt;</phrase> <phrase role="identifier">Channel</phrase> <phrase
+ role="special">&gt;::</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">&lt;</phrase> <phrase
+ role="identifier">Channel</phrase> <phrase role="special">&gt;::</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">&lt;</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">&lt;</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">&gt;</phrase> <phrase
+ role="special">&gt;</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">&lt;</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;</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">&lt;</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;</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">&lt;</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">&lt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">type</phrase><phrase role="special">).</phrase><phrase role="identifier">name</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;</phrase></code>.
+ </para>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase> <phrase role="special">&lt;&lt;</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">&lt;</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">&lt;</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">&gt;</phrase>
+ <phrase role="special">&gt;</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">&lt;</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">&lt;</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">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;&lt;</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">&lt;&lt;</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">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;::</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">&lt;</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">&lt;</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">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;&lt;</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">&lt;&lt;</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">&lt;</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">&lt;</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">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;&lt;</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">&lt;&lt;</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">&lt;</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">&lt;</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">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;&lt;</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">&lt;&lt;</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">&lt;</phrase>
+ <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="keyword">const</phrase><phrase role="special">&amp;)</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">&lt;</phrase> <phrase role="identifier">Pool</phrase> <phrase
+ role="special">&gt;()</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">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">SchedulingPolicy</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">SchedulingPolicy</phrase> <phrase role="special">&gt;</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">&lt;</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">&lt;</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&gt;</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">&lt;</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">&lt;</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">&lt;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;,</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">&gt;</phrase>
+ <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;=</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">&lt;=</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;=</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">&lt;=</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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&lt; tp::unbounded_channel&lt; tp::fifo &gt; &gt; 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">&lt;=</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">&lt;=</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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">&lt;=</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">&lt;=</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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 &lt;= 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">&lt;=</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;().</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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 &lt;= offset</emphasis>)
+ return seq_( n); else { tp::task&lt; int &gt; t1( boost::this_task::get_thread_pool&lt;
+ pool<emphasis role="underline">type &gt;().submit( boost::bind( &amp; fibo::par</emphasis>,
+ boost::ref( * this), n - 1) ) ); tp::task&lt; int &gt; t2( boost::this_task::get_thread_pool&lt;
+ pool<emphasis role="underline">type &gt;().submit( boost::bind( &amp; 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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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&lt; tp::task&lt; int &gt; &gt; 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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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">&lt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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 &lt; 32; ++i) results.push_back( pool.submit( boost::bind(
+ &amp; 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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;::</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">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot; == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">i</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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&lt; tp::task&lt; int &gt; &gt;::iterator e( results.end()
+ ); for ( std::vector&lt; tp::task&lt; int &gt; &gt;::iterator i( results.begin()
+ ); i != e; ++i) std::cout &lt;&lt; &quot;fibonacci &quot; &lt;&lt; k++ &lt;&lt;
+ &quot; == &quot; &lt;&lt; i-&gt;result().get() &lt;&lt; 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">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot; milli seconds&quot;</phrase> <phrase role="special">&lt;&lt;</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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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 &lt;&lt;
+ ( stop - start).total_milliseconds() &lt;&lt; &quot; milli seconds&quot; &lt;&lt;
+ 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">&amp;</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">&lt;&lt;</phrase> <phrase role="string">&quot;exception: &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</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">&lt;&lt;</phrase> <phrase role="string">&quot;unhandled&quot;</phrase> <phrase role="special">&lt;&lt;</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&amp; e) { std::cerr &lt;&lt;
+ &quot;exception: &quot; &lt;&lt; e.what() &lt;&lt; std::endl; } catch ( ...
+ ) { std::cerr &lt;&lt; &quot;unhandled&quot; &lt;&lt; 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">&lt;</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">&gt;</phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Channel</phrase> <phrase role="special">&gt;</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">&amp;</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">&amp;</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">&amp;</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">&amp;</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</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">&amp;</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">&amp;</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">&amp;</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">&amp;</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">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</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">&amp;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">callable</phrase> <phrase role="special">&gt;</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">&amp;</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">&amp;</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">type</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">act</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</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">&gt;</phrase>
+ <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">type</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">act</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">Attr</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">attr</phrase><phrase role="special">);</phrase>
+ <phrase role="special">};</phrase>
+
+<phrase role="identifier">pool</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">fifo</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</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">&amp;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">&gt;</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">&amp;</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">&amp;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">&gt;</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">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</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">&amp;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">&gt;</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">&amp;</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</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">&amp;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">&gt;</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">&lt;</phrase>
+ <phrase role="identifier">Channel</phrase> <phrase role="special">&gt;::</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">&lt;</phrase> <phrase role="identifier">callable</phrase> <phrase role="special">&gt;</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">&amp;</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">&amp;</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">-&gt;</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">&amp;</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">&amp;</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">-&gt;</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">&amp;</phrase> <phrase role="identifier">act</phrase><phrase
+ role="special">)</phrase></code></link></title>
+<programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">type</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">act</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ has_priority&lt; pool &gt;::value == false &amp;&amp; ! ( 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">&amp;</phrase> <phrase role="identifier">act</phrase><phrase
+ role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase
+ role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase
+ role="identifier">attr</phrase><phrase role="special">)</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</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">&gt;</phrase>
+<phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">type</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">act</phrase><phrase role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">attr</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ has_priority&lt; pool &gt;::value == true &amp;&amp; ! ( 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">&lt;</phrase> <phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">fifo</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</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">&lt;</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">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</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">&amp;</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">&amp;</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Duration</phrase> <phrase role="special">&gt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">&gt;</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">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">R</phrase>
+ <phrase role="special">&gt;</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">&amp;</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">);</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">DurationTime</phrase> <phrase role="special">&gt;</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">&amp;</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">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</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">&lt;</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">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</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">&gt;</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">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;);</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</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">&gt;</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">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;);</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">&lt;</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">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">Pool</phrase> <phrase role="special">&amp;</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">&lt;</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">&gt;</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 &gt; 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 () &gt; 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">&lt;</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">&gt;</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 &gt;= 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 () &gt;= 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">&lt;</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">&gt;</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">&lt;</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">&gt;</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">&lt;</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">&gt;</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">&amp;</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">&amp;</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">&lt;</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">&gt;</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">&amp;</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">&amp;</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">&lt;</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">&gt;</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">&amp;</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">&amp;</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">&lt;</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">&gt;</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">&amp;</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">&amp;</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">&lt;</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">&gt;</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">&amp;</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">&amp;</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">&lt;</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">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">&gt;</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">&lt;</phrase>
+ <phrase role="identifier">is_same</phrase><phrase role="special">&lt;</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">&gt;::</phrase><phrase role="identifier">value</phrase>
+<phrase role="special">&gt;</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">&lt;</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">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">&gt;</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>

Added: sandbox/task/libs/task/doc/watermark_ref.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/watermark_ref.qbk 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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

Added: sandbox/task/libs/task/examples/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/Jamfile.v2 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,28 @@
+# 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 bind_to_processor : bind_to_processor.cpp ;
+exe delay : delay.cpp ;
+exe fork_join : for_join.cpp ;
+exe interrupt : interrupt.cpp ;
+exe pending : pending.cpp ;
+exe priority : priority.cpp ;
+exe reschedule_until : reschedule_until.cpp ;
+exe shutdonw_now : shutdonw_now.cpp ;
+exe smart : smart.cpp ;
+exe submit : submit.cpp ;
+exe yield : yield.cpp ;

Added: sandbox/task/libs/task/examples/bind_to_processors.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/bind_to_processors.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,109 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+typedef tsk::pool< tsk::unbounded_channel< tsk::fifo > > pool_type;
+
+long serial_fib( long n)
+{
+ if( n < 2)
+ return n;
+ else
+ return serial_fib( n - 1) + serial_fib( n - 2);
+}
+
+class fib_task
+{
+private:
+ long cutof_;
+
+public:
+ fib_task( long cutof)
+ : cutof_( cutof)
+ {}
+
+ long execute( long n)
+ {
+ if ( n < cutof_) return serial_fib( n);
+ else
+ {
+ tsk::task< long > t1(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) ) ;
+ tsk::task< long > t2(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) );
+ tsk::launch_in_pool(
+ boost::this_task::get_pool< pool_type >(),
+ t1);
+ tsk::launch_in_pool(
+ boost::this_task::get_pool< pool_type >(),
+ t2);
+ return t1.get() + t2.get();
+ }
+ }
+};
+
+
+long parallel_fib( long n)
+{
+ fib_task a( 5);
+ return a.execute( n);
+}
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ pool_type pool;
+
+ std::vector< tsk::task< long > > results;
+ results.reserve( 20);
+
+ pt::ptime start( pt::microsec_clock::universal_time() );
+
+ for ( int i = 0; i < 26; ++i)
+ {
+ tsk::task< long > t(
+ tsk::make_task(
+ & parallel_fib,
+ i) );
+ results.push_back( t);
+ tsk::launch_in_pool( pool, t);
+ }
+
+ tsk::waitfor_all( results.begin(), results.end() );
+
+ int k = 0;
+ std::vector< tsk::task< long > >::iterator e( results.end() );
+ for (
+ std::vector< tsk::task< long > >::iterator i( results.begin() );
+ i != e;
+ ++i)
+ std::cout << "fibonacci " << k++ << " == " << i->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;
+}

Added: sandbox/task/libs/task/examples/delay.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/delay.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,85 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+long serial_fib( long n)
+{
+ if( n < 2)
+ return n;
+ else
+ return serial_fib( n - 1) + serial_fib( n - 2);
+}
+
+class fib_task
+{
+private:
+ long cutof_;
+
+public:
+ fib_task( long cutof)
+ : cutof_( cutof)
+ {}
+
+ long execute( long n)
+ {
+ if ( n < cutof_)
+ {
+ if ( n == 0)
+ boost::this_task::delay( pt::seconds( 2) );
+ return serial_fib( n);
+ }
+ else
+ {
+ tsk::task< long > t1(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) );
+ tsk::task< long > t2(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) );
+ tsk::launch_in_pool( t1);
+ tsk::launch_in_pool( t2);
+ return t1.get() + t2.get();
+ }
+ }
+};
+
+
+void parallel_fib( long n)
+{
+ fib_task a( 5);
+ long result = a.execute( n);
+ printf("n == %d, fibonnaci == %d\n", n, result);
+}
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ for ( int i = 0; i < 10; ++i)
+ tsk::launch_in_pool(
+ tsk::make_task(
+ & parallel_fib,
+ i) );
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}

Added: sandbox/task/libs/task/examples/fork_join.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/fork_join.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,108 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+typedef tsk::pool< tsk::unbounded_channel< tsk::fifo > > pool_type;
+
+long serial_fib( long n)
+{
+ if( n < 2)
+ return n;
+ else
+ return serial_fib( n - 1) + serial_fib( n - 2);
+}
+
+class fib_task
+{
+private:
+ long cutof_;
+
+public:
+ fib_task( long cutof)
+ : cutof_( cutof)
+ {}
+
+ long execute( long n)
+ {
+ if ( n < cutof_) return serial_fib( n);
+ else
+ {
+ tsk::task< long > t1(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) );
+ tsk::task< long > t2(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) );
+ tsk::launch_in_pool(
+ boost::this_task::get_pool< pool_type >(),
+ t1);
+ tsk::launch_in_pool(
+ boost::this_task::get_pool< pool_type >(),
+ t2);
+ return t1.get() + t2.get();
+ }
+ }
+};
+
+long parallel_fib( long n)
+{
+ fib_task a( 5);
+ return a.execute( n);
+}
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ pool_type pool( tsk::poolsize( 5) );
+
+ std::vector< tsk::task< long > > results;
+ results.reserve( 20);
+
+ pt::ptime start( pt::microsec_clock::universal_time() );
+
+ for ( int i = 0; i < 26; ++i)
+ {
+ tsk::task< long > t(
+ tsk::make_task(
+ & parallel_fib,
+ i) );
+ results.push_back( t);
+ tsk::launch_in_pool( pool, t);
+ }
+
+ tsk::waitfor_all( results.begin(), results.end() );
+
+ int k = 0;
+ std::vector< tsk::task< long > >::iterator e( results.end() );
+ for (
+ std::vector< tsk::task< long > >::iterator i( results.begin() );
+ i != e;
+ ++i)
+ std::cout << "fibonacci " << k++ << " == " << i->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;
+}

Added: sandbox/task/libs/task/examples/interrupt.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/interrupt.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,63 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+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
+ {
+ tsk::launch_in_pool(
+ tsk::make_task(
+ long_running_fn) );
+ std::cout << "poolsize == " << tsk::get_default_pool().size() << std::endl;
+ std::cout << "idle threads == " << tsk::get_default_pool().idle() << std::endl;
+ std::cout << "active threads == " << tsk::get_default_pool().active() << std::endl;
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_pool( t);
+ t.interrupt();
+ std::cout << t.get() << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( tsk::task_interrupted const& )
+ { std::cerr << "task_interrupted: task 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;
+}

Added: sandbox/task/libs/task/examples/pending.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/pending.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,59 @@
+#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/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+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
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_pool(
+ tsk::make_task(
+ long_running_fn) );
+ tsk::launch_in_pool( t);
+ std::cout << "pending tasks == " << tsk::get_default_pool().pending() << std::endl;
+ std::cout << t.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;
+}

Added: sandbox/task/libs/task/examples/priority.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/priority.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,62 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <string>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+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
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::priority< int > >
+ > pool( tsk::poolsize( 1) );
+
+ tsk::launch_in_pool(
+ pool,
+ tsk::make_task(
+ long_running_fn),
+ 0);
+ tsk::launch_in_pool(
+ pool,
+ tsk::make_task(
+ print_fn,
+ "This"),
+ 0);
+ tsk::launch_in_pool(
+ pool,
+ tsk::make_task(
+ print_fn,
+ "a text.\n"),
+ 2);
+ tsk::launch_in_pool(
+ pool,
+ tsk::make_task(
+ 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;
+}

Added: sandbox/task/libs/task/examples/reschedule_until.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/reschedule_until.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,161 @@
+#include <cerrno>
+#include <cstddef>
+#include <cstring>
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <string>
+
+extern "C"
+{
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+}
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/thread.hpp>
+
+#include "boost/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+long serial_fib( long n)
+{
+ if( n < 2)
+ return n;
+ else
+ return serial_fib( n - 1) + serial_fib( n - 2);
+}
+
+class fib_task
+{
+private:
+ long cutof_;
+
+public:
+ fib_task( long cutof)
+ : cutof_( cutof)
+ {}
+
+ long execute( long n)
+ {
+ if ( n < cutof_) return serial_fib( n);
+ else
+ {
+ tsk::task< long > t1(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) );
+ tsk::task< long > t2(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) );
+ tsk::launch_in_pool( t1);
+ tsk::launch_in_pool( t2);
+ return t1.get() + t2.get();
+ }
+ }
+};
+
+void parallel_fib( long n)
+{
+ fib_task a( 5);
+ printf("%d -> %d\n", n, a.execute( n) );
+}
+
+bool has_bytes( int fd)
+{
+ char buffer[1];
+
+ int n = ::recv(
+ fd,
+ & buffer,
+ sizeof buffer,
+ MSG_PEEK | MSG_DONTWAIT);
+ if ( n == -1 && errno != EWOULDBLOCK)
+ {
+ printf("::recv() failed: %s(%d)\n", std::strerror( errno), errno);
+ ::exit( 1);
+ }
+
+ return n > 0;
+}
+
+void read( int fd)
+{
+ int nread = 0;
+ do
+ {
+ boost::this_task::reschedule_until(
+ boost::bind(
+ has_bytes,
+ fd) );
+
+ char buffer[4096];
+ int n = ::read( fd, buffer, sizeof( buffer) );
+ if ( n < 0)
+ {
+ printf("::read() failed: %s(%d)\n", std::strerror( errno), errno);
+ ::exit( 1);
+ }
+ nread += n;
+ printf("%s\n", std::string( buffer, n).c_str() );
+ }
+ while ( nread < 12);
+}
+
+void write( int fd, std::string const& msg)
+{
+ if ( ::write( fd, msg.c_str(), msg.size() ) < 0)
+ {
+ printf("::write() failed: %s(%d)\n", std::strerror( errno), errno);
+ ::exit( 1);
+ }
+}
+
+void create_sockets( int fd[2])
+{
+ if ( ::socketpair( PF_LOCAL, SOCK_STREAM, 0, fd) < 0)
+ {
+ printf("::pipe() failed: %s(%d)\n", std::strerror( errno), errno);
+ ::exit( 1);
+ }
+}
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ int fd[2];
+ create_sockets( fd);
+
+ tsk::launch_in_pool(
+ tsk::make_task(
+ & read,
+ fd[0]) );
+
+ write( fd[1], "Hello ");
+ boost::this_thread::sleep( pt::seconds( 1) );
+
+ for ( int i = 0; i < 15; ++i)
+ tsk::launch_in_pool(
+ tsk::make_task(
+ & parallel_fib,
+ i) );
+
+ write( fd[1], "World!");
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}

Added: sandbox/task/libs/task/examples/shutdonw_now.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/shutdonw_now.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,63 @@
+#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/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+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
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_pool( pool, t);
+
+ boost::this_thread::sleep( pt::milliseconds( 250) );
+
+ pool.shutdown_now();
+
+ std::cout << t.get() << std::endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch ( tsk::task_interrupted const& )
+ { std::cerr << "task_interrupted: task 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;
+}

Added: sandbox/task/libs/task/examples/smart.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/smart.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,88 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <string>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+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
+ {
+ tsk::pool<
+ tsk::unbounded_channel<
+ tsk::smart<
+ int,
+ std::less< int >,
+ tsk::replace_oldest,
+ tsk::take_oldest
+ >
+ >
+ > pool( tsk::poolsize( 1) );
+
+ tsk::launch_in_pool(
+ pool,
+ tsk::make_task(
+ long_running_fn),
+ 0);
+ tsk::launch_in_pool(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 0),
+ 1);
+ tsk::launch_in_pool(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 1),
+ 2);
+ tsk::launch_in_pool(
+ pool,
+ tsk::make_task(
+ 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;
+}

Added: sandbox/task/libs/task/examples/submit.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/submit.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,59 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+
+#include <boost/bind.hpp>
+
+#include "boost/task.hpp"
+
+namespace tsk = boost::task;
+
+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
+ {
+ tsk::task< int > t1(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::task< int > t2(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::task< int > t3(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_pool( t1);
+ tsk::launch_in_thread( t2);
+ tsk::launch_local( t3);
+ std::cout << t1.get() << std::endl;
+ std::cout << t2.get() << std::endl;
+ std::cout << t3.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;
+}

Added: sandbox/task/libs/task/examples/yield.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/examples/yield.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,95 @@
+#include <iostream>
+#include <cstdlib>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include "boost/task.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+typedef tsk::default_pool pool_type;
+
+long serial_fib( long n)
+{
+ if( n < 2)
+ return n;
+ else
+ return serial_fib( n - 1) + serial_fib( n - 2);
+}
+
+class fib_task
+{
+private:
+ long cutof_;
+
+public:
+ fib_task( long cutof)
+ : cutof_( cutof)
+ {}
+
+ long execute( long n)
+ {
+ if ( n == 7)
+ boost::this_task::yield();
+
+ if ( n < cutof_)
+ return serial_fib( n);
+ else
+ {
+ tsk::task< long > t1(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) );
+ tsk::task< long > t2(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) );
+ if ( boost::this_task::runs_in_pool() )
+ {
+ tsk::launch_in_pool( t1);
+ tsk::launch_in_pool( t2);
+ }
+ else
+ {
+ tsk::launch_in_thread( t1);
+ tsk::launch_in_thread( t2);
+ }
+ return t1.get() + t2.get();
+ }
+ }
+};
+
+
+void parallel_fib( long n)
+{
+ fib_task a( 5);
+ long result = a.execute( n);
+ printf("n == %d, fibonnaci == %d\n", n, result);
+}
+
+int main( int argc, char *argv[])
+{
+ try
+ {
+ for ( int i = 0; i < 10; ++i)
+ tsk::launch_in_thread(
+// tsk::launch_in_pool(
+ tsk::make_task(
+ & parallel_fib,
+ i) );
+
+ return EXIT_SUCCESS;
+ }
+ catch ( std::exception const& e)
+ { std::cerr << "exception: " << e.what() << std::endl; }
+ catch ( ... )
+ { std::cerr << "unhandled" << std::endl; }
+
+ return EXIT_FAILURE;
+}

Added: sandbox/task/libs/task/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/Jamfile.v2 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,33 @@
+# 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>../../test/build//boost_unit_test_framework
+ <library>../../thread/build//boost_thread
+ <library>../../system/build//boost_system
+ <library>../../task/build//boost_task
+ <link>static
+ <threading>multi
+ ;
+
+rule tp-test ( source )
+{
+ return
+ [ run $(source).cpp ]
+ ;
+}
+
+test-suite thread_pool :
+ [ tp-test test_pool_bounded_channel ]
+ [ tp-test test_pool_unbounded_channel ]
+ [ tp-test test_launch ]
+ ;

Added: sandbox/task/libs/task/test/test_functions.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_functions.hpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,65 @@
+// 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/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/task.hpp>
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+void barrier_fn(
+ boost::barrier & b)
+{ b.wait(); }
+
+void delay_fn( pt::time_duration const& td)
+{ boost::this_thread::sleep( td); }
+
+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
+bool runs_in_pool_fn()
+{ return boost::this_task::runs_in_pool(); }
+
+inline
+void throwing_fn()
+{ throw std::runtime_error("exception thrown"); }
+
+#endif // BOOST_TP_TEST_FUNCTIONS_H

Added: sandbox/task/libs/task/test/test_launch.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_launch.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 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)
+
+#include <cstdlib>
+#include <iostream>
+#include <map>
+#include <stdexcept>
+#include <vector>
+
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/function.hpp>
+#include <boost/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+class test_launch
+{
+public:
+ // launch in default pool
+ void test_case_1()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_pool( t);
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ }
+
+ // launch in custom pool
+ void test_case_2()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_pool( pool, t);
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ }
+
+ // launch in new thread
+ void test_case_3()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_thread( t);
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ }
+
+ // launch in current thread
+ void test_case_4()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_current( t);
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ }
+
+ // don't execute twice
+ void test_case_5()
+ {
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ tsk::launch_in_current( t);
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ tsk::launch_in_current( t);
+ bool thrown( false);
+ try
+ { t.get(); }
+ catch ( tsk::task_already_executed const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check runs in pool
+ void test_case_6()
+ {
+ tsk::task< bool > t(
+ tsk::make_task(
+ runs_in_pool_fn) );
+ tsk::launch_in_pool( t);
+ BOOST_CHECK_EQUAL( t.get(), true);
+ }
+
+ // check runs not in pool
+ void test_case_7()
+ {
+ tsk::task< bool > t(
+ tsk::make_task(
+ runs_in_pool_fn) );
+ tsk::launch_in_thread( t);
+ BOOST_CHECK_EQUAL( t.get(), false);
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: pool (with unbounded channel) test suite") );
+
+ boost::shared_ptr< test_launch > instance( new test_launch() );
+ test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_launch::test_case_7, instance) );
+
+ return test;
+}

Added: sandbox/task/libs/task/test/test_pool_bounded_channel.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_pool_bounded_channel.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,400 @@
+// 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/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+class test_pool_bounded_channel
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 3),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ pool.submit( t);
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ pool.submit( t);
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ tsk::task< void > t(
+ tsk::make_task(
+ throwing_fn) );
+ pool.submit( t);
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ tsk::make_task(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ }
+ catch ( tsk::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 1),
+ tsk::low_watermark( 1) );
+ tsk::task< void > t(
+ tsk::make_task(
+ delay_fn,
+ pt::millisec( 500) ) );
+ pool.submit( t);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ tsk::task< void > t1(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ pool.submit( t1);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tsk::task< int > t2(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ pool.submit( t2);
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tsk::task< int > t3(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ pool.submit( t3);
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ t1.get();
+ BOOST_CHECK_EQUAL( t2.get(), 55);
+ BOOST_CHECK_EQUAL( t3.get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check interruption
+ void test_case_8()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tsk::task< void > t(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit( t);
+ pool.submit(
+ tsk::make_task(
+ 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.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check fifo scheduling
+ void test_case_9()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 55);
+ BOOST_CHECK_EQUAL( buffer[1], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check lifo scheduling
+ void test_case_10()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::lifo >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check priority scheduling
+ void test_case_11()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::priority< int > >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 1);
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 0);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check smart scheduling
+ void test_case_12()
+ {
+ typedef tsk::pool<
+ tsk::bounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
+ > pool_type;
+ pool_type pool(
+ tsk::poolsize( 1),
+ tsk::high_watermark( 10),
+ tsk::low_watermark( 10) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 2);
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 1);
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 1),
+ 2);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 1);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: pool (with bounded channel) test suite") );
+
+ boost::shared_ptr< test_pool_bounded_channel > instance( new test_pool_bounded_channel() );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_9, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_10, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_11, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_bounded_channel::test_case_12, instance) );
+
+ return test;
+}
+

Added: sandbox/task/libs/task/test/test_pool_unbounded_channel.cpp
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/test/test_pool_unbounded_channel.cpp 2009-04-17 12:19:06 EDT (Fri, 17 Apr 2009)
@@ -0,0 +1,363 @@
+// 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/ref.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/thread.hpp>
+#include <boost/thread/barrier.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/task.hpp>
+
+#include "test_functions.hpp"
+
+namespace pt = boost::posix_time;
+namespace tsk = boost::task;
+
+class test_pool_unbounded_channel
+{
+public:
+ // check size, active, idle
+ void test_case_1()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 3) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 3) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ }
+
+ // check submit
+ void test_case_2()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ pool.submit( t);
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ }
+
+ // check shutdown
+ void test_case_3()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::task< int > t(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ pool.submit( t);
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( t.get(), 55);
+ }
+
+ // check runtime_error throw inside task
+ void test_case_4()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::task< void > t(
+ tsk::make_task(
+ throwing_fn) );
+ pool.submit( t);
+ pool.shutdown();
+ bool thrown( false);
+ try
+ { t.get(); }
+ catch ( std::runtime_error const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown with task_rejected exception
+ void test_case_5()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ pool.shutdown();
+ BOOST_CHECK( pool.closed() );
+ bool thrown( false);
+ try
+ {
+ pool.submit(
+ tsk::make_task(
+ boost::bind(
+ fibonacci_fn,
+ 10) ) );
+ }
+ catch ( tsk::task_rejected const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check shutdown_now with thread_interrupted exception
+ void test_case_6()
+ {
+ tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool( tsk::poolsize( 1) );
+ tsk::task< void > t(
+ tsk::make_task(
+ delay_fn,
+ pt::millisec( 500) ) );
+ pool.submit( t);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ pool.shutdown_now();
+ BOOST_CHECK( pool.closed() );
+ BOOST_CHECK_EQUAL( pool.size(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.idle(), std::size_t( 1) );
+ BOOST_CHECK_EQUAL( pool.active(), std::size_t( 0) );
+ bool thrown( false);
+ try
+ { t.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check pending
+ void test_case_7()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ tsk::task< void > t1(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ pool.submit( t1);
+ boost::this_thread::sleep( pt::millisec( 250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ tsk::task< int > t2(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ pool.submit( t2);
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 1) );
+ tsk::task< int > t3(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) );
+ pool.submit( t3);
+ boost::this_thread::sleep( pt::millisec(250) );
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 2) );
+ b.wait();
+ t1.get();
+ BOOST_CHECK_EQUAL( t2.get(), 55);
+ BOOST_CHECK_EQUAL( t3.get(), 55);
+ BOOST_CHECK_EQUAL( pool.pending(), std::size_t( 0) );
+ }
+
+ // check interruptation
+ void test_case_8()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ tsk::task< void > t(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit( t);
+ pool.submit(
+ tsk::make_task(
+ 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.get(); }
+ catch ( tsk::task_interrupted const&)
+ { thrown = true; }
+ BOOST_CHECK( thrown);
+ }
+
+ // check fifo scheduling
+ void test_case_9()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::fifo >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 55);
+ BOOST_CHECK_EQUAL( buffer[1], 0);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check lifo scheduling
+ void test_case_10()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::lifo >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ) );
+ std::vector< int > buffer;
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10) );
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0) );
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check priority scheduling
+ void test_case_11()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::priority< int > >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 1);
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 0);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 55);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+
+ // check smart scheduling
+ void test_case_12()
+ {
+ typedef tsk::pool<
+ tsk::unbounded_channel< tsk::smart< int, std::less< int >, tsk::replace_oldest, tsk::take_oldest > >
+ > pool_type;
+ pool_type pool( tsk::poolsize( 1) );
+ boost::barrier b( 2);
+ pool.submit(
+ tsk::make_task(
+ barrier_fn,
+ boost::ref( b) ),
+ 0);
+ std::vector< int > buffer;
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 10),
+ 2);
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 0),
+ 1);
+ pool.submit(
+ tsk::make_task(
+ buffer_fibonacci_fn,
+ boost::ref( buffer),
+ 1),
+ 2);
+ b.wait();
+ pool.shutdown();
+ BOOST_CHECK_EQUAL( buffer[0], 0);
+ BOOST_CHECK_EQUAL( buffer[1], 1);
+ BOOST_CHECK_EQUAL( buffer.size(), std::size_t( 2) );
+ }
+};
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+ boost::unit_test::test_suite * test( BOOST_TEST_SUITE("Boost.ThreadPool: pool (with unbounded channel) test suite") );
+
+ boost::shared_ptr< test_pool_unbounded_channel > instance( new test_pool_unbounded_channel() );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_1, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_2, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_3, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_4, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_5, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_6, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_7, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_8, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_9, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_10, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_11, instance) );
+ test->add( BOOST_CLASS_TEST_CASE( & test_pool_unbounded_channel::test_case_12, instance) );
+
+ return test;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk