|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52942 - in sandbox/task: boost/task libs/task/doc libs/task/examples
From: oliver.kowalke_at_[hidden]
Date: 2009-05-12 14:33:34
Author: olli
Date: 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
New Revision: 52942
URL: http://svn.boost.org/trac/boost/changeset/52942
Log:
* some updates to documentations
* corrections of handle.hpp and async.hpp related to as_sub_task
* examples modified
Added:
sandbox/task/libs/task/doc/acknowledgements.qbk (contents, props changed)
sandbox/task/libs/task/doc/appendices.qbk (contents, props changed)
sandbox/task/libs/task/doc/boost_task.qbk (contents, props changed)
sandbox/task/libs/task/doc/overview.qbk (contents, props changed)
sandbox/task/libs/task/doc/rationale.qbk (contents, props changed)
sandbox/task/libs/task/doc/todo.qbk (contents, props changed)
Removed:
sandbox/task/libs/task/doc/acknowledgement.qbk
sandbox/task/libs/task/doc/threadpool.qbk
sandbox/task/libs/task/doc/threadpool.xml
Text files modified:
sandbox/task/boost/task/async.hpp | 1
sandbox/task/boost/task/handle.hpp | 3 +
sandbox/task/libs/task/doc/Jamfile.v2 | 15 ++---
sandbox/task/libs/task/doc/introduction.qbk | 100 ++++++++++++++++++++++++++++++++++-----
sandbox/task/libs/task/examples/delay.cpp | 4
sandbox/task/libs/task/examples/fork_join.cpp | 60 ++++++++---------------
6 files changed, 121 insertions(+), 62 deletions(-)
Modified: sandbox/task/boost/task/async.hpp
==============================================================================
--- sandbox/task/boost/task/async.hpp (original)
+++ sandbox/task/boost/task/async.hpp 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -75,6 +75,7 @@
detail::worker * w( detail::worker::tss_get() );
if ( w)
{
+ detail::interrupter intr;
shared_future< R > fut( t.get_future() );
function< bool() > wcb(
bind(
Modified: sandbox/task/boost/task/handle.hpp
==============================================================================
--- sandbox/task/boost/task/handle.hpp (original)
+++ sandbox/task/boost/task/handle.hpp 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -23,6 +23,7 @@
struct own_thread;
struct new_thread;
+struct as_sub_task;
template< typename R >
class handle
@@ -32,6 +33,7 @@
friend class pool;
friend struct own_thread;
friend struct new_thread;
+ friend struct as_sub_task;
template< typename Iterator >
friend void waitfor_all( Iterator begin, Iterator end);
template< typename T1, typename T2 >
@@ -136,6 +138,7 @@
friend class pool;
friend struct own_thread;
friend struct new_thread;
+ friend struct as_sub_task;
template< typename Iterator >
friend void waitfor_all( Iterator begin, Iterator end);
template< typename T1, typename T2 >
Modified: sandbox/task/libs/task/doc/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/doc/Jamfile.v2 (original)
+++ sandbox/task/libs/task/doc/Jamfile.v2 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -1,12 +1,11 @@
-# Boost.ThreadPool Library Documentation Jamfile
+# Boost.Task 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)
+# Copyright Oliver Kowalke 2009.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt
using quickbook ;
-xml threadpool : threadpool.qbk ;
-boostbook standalone : threadpool ;
+xml task : boost_task.qbk ;
+boostbook standalone : task ;
Deleted: sandbox/task/libs/task/doc/acknowledgement.qbk
==============================================================================
--- sandbox/task/libs/task/doc/acknowledgement.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
+++ (empty file)
@@ -1,11 +0,0 @@
-[/
- (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/acknowledgements.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/acknowledgements.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -0,0 +1,12 @@
+[/
+ Copyright Oliver Kowalke 2009.
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+]
+
+
+[section:acknowledgements Appendix B: Acknowledgments]
+I'd like to thank Vicente J. Botet Escriba for his comments on the implementation and Anthony Williams and Braddock Gaskill for their future libraries.
+
+[endsect]
Added: sandbox/task/libs/task/doc/appendices.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/appendices.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -0,0 +1,20 @@
+[/
+ Copyright Oliver Kowalke 2009.
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+]
+
+
+[section Appendices]
+
+[include rationale.qbk]
+
+[include acknowledgements.qbk]
+
+[include todo.qbk]
+
+[endsect]
+
+
+
Added: sandbox/task/libs/task/doc/boost_task.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/boost_task.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -0,0 +1,80 @@
+[/
+ Copyright Oliver Kowalke 2009.
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+]
+
+
+[library Boost.Task
+ [quickbook 1.4]
+ [authors [Kowalke, Oliver]]
+ [copyright 2009 Oliver Kowalke]
+ [purpose C++ Library for asynchronous execution of tasks]
+ [category text]
+ [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])
+ ]
+]
+
+[def __boost__ [*boost-1.39.0]]
+[def __boost_task__ [*Boost.Task]]
+[def __boost_thread__ [@http://www.boost.org/libs/thread [*Boost.Thread]]]
+[def __boost_future__ [@http://www.justsoftwaresolutions.co.uk/threading/updated-implementation-of-c++-futures-3.html [*Boost.Future]]]
+
+[template link_coop_task[link_text] [link boost_task.cooperative_task [link_text]]]
+[template link_channel[link_text] [link boost_task.channel [link_text]]]
+[template link_forkjoin[link_text] [link boost_task.forkjoin [link_text]]]
+[template link_task[link_text] [link boost_task.task [link_text]]]
+[template link_ws[link_text] [link boost_task.pool.work_stealing [link_text]]]
+
+[def __hardware_concurrency__ `boost::thread::hardware_concurrency()`]
+[def __thread__ `boost::thread`]
+
+[def __as_sub_task__ `as_sub_task`]
+[def __bounded_channel__ `bounded_channel`]
+[def __duration__ `Duration`]
+[def __handle__ `handle`]
+[def __new_thread__ `new_thread`]
+[def __own_thread__ `own_thread`]
+[def __task__ `task`]
+[def __system_time__ `system_time`]
+[def __unbounded_channel__ `unbounded_channel`]
+
+[def __async__ `async()`]
+[def __default_pool__ `default_pool()`]
+[def __delay__ `delay()`]
+[def __get__ `get()`]
+[def __get_id__ `get_id()`]
+[def __get_pool__ `get_pool()`]
+[def __has_value__ `has_value()`]
+[def __has_exception__ `has_exception()`]
+[def __interrupt__ `interrupt()`]
+[def __interrupt_and_wait__ `interrupt_and_wait()`]
+[def __interruption_requested__ `interruption_requested()`]
+[def __is_ready__ `is_ready()`]
+[def __make_task__ `make_task()`]
+[def __reschedule_until__ `reschedule_until()`]
+[def __runs_in_pool__ `runs_in_pool()`]
+[def __wait__ `wait()`]
+[def __worker_id__ `worker_id()`]
+[def __yield__ `yield()`]
+
+[def __act__ `asynchronous-completion-token`]
+[def __ae__ `asynchronous-executor`]
+[def __aes__ `asynchronous-executors`]
+[def __blocked__ ['blocked]]
+[def __fork_join__ ['fork/join]]
+[def __interruption_point__ ['interruption point]]
+[def __task_id__ ['task id]]
+[def __thread_pool__ ['thread pool]]
+[def __work_stealing__ ['work stealing]]
+[def __worker_queue__ ['worker queue]]
+[def __worker_thread__ ['worker thread]]
+
+
+[include overview.qbk]
+[include reference.qbk]
+[include appendices.qbk]
Modified: sandbox/task/libs/task/doc/introduction.qbk
==============================================================================
--- sandbox/task/libs/task/doc/introduction.qbk (original)
+++ sandbox/task/libs/task/doc/introduction.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -8,27 +8,99 @@
[section:motivation Motivation]
-In order to take advantage of the technological evolution from single-core to many-core architectures multi-core machines requires to partition the compute bound work into smaller chunks that can run in parallel.
+In order to take advantage of the technological evolution from single-core to many-core architectures multi-core machines,
+partitioning the compute bound work into smaller chunks that can run in parallel is required.
+The code can scale as the hardware gets better without changing the code (achieving desired load balancing).
-The goal of parallel programming is to write once and have our code scale well as the hardware underneath it gets better, i.e. see incremental benefits when running our app on machines with more cores without changing the code.
-
-Had we partitioned the work into much smaller chunks, when a core is finished with the item it executes, it would be able to start working on another chunk hence achieving the desired load balancing.
+[note Equating multithreading to parallelism is not accurate. You can have multithreading on a single-core machine,
+but you can only have parallelism on a multi-core machine (portions of your code that can truly run at the same time).]
__boost_task__ provides a framework to utilize the available hardware and provide a way for efficient asynchronous processing of time consuming operations in the same process.
-[note Equating multithreading to parallelism is not accurate. You can have multithreading on a single-core machine, but you can only have parallelism on a multi-core machine. the portions of your code that can truly run at the same time.]
-
-[heading Executing a task]
+The framework provides some __aes__, like __new_thread__, in order to launch __task__ in a new thread:
std::string echo( std::string const& msg)
{ return msg; }
- boost::task::handle< std::string > h(
- boost::task::async(
- boost::task::new_thread(),
- boost::task::make_task(
- echo,
- "Hello World!") ) );
- std::cout << h.get() << std::endl;
+ void main()
+ {
+ boost::task::handle< std::string > h(
+ boost::task::async(
+ boost::task::new_thread(),
+ boost::task::make_task(
+ echo,
+ "Hello World!") ) );
+ std::cout << h.get() << std::endl;
+ }
+
+__handle__ manages the __task__ and allows to transfer the result to the caller thread.
+
+With __runs_in_pool__ the task can detect if it is running inside a __thread_pool__ (executed by a __worker_thread__) at runtime.
+
+ long serial_fib( long n)
+ {
+ if( n < 2) return n;
+ else return serial_fib( n - 1) + serial_fib( n - 2);
+ }
+
+ long parallel_fib( long n, long cutof)
+ {
+ if ( n < cutof) return serial_fib( n);
+ else
+ {
+ boost::task::handle< long > h1, h2;
+ if ( boost::this_task::runs_in_pool() )
+ {
+ // task is executed inside a thread-pool
+ // the sub-tasks are submitted to the thread-local
+ // worker-queue for speed improvments
+ h1 = boost::task::async(
+ boost::this_task::as_sub_task(),
+ boost::task::make_task(
+ parallel_fib,
+ n - 1,
+ cutof) );
+ h2 = boost::task::async(
+ boost::this_task::as_sub_task(),
+ boost::task::make_task(
+ parallel_fib,
+ n - 2,
+ cutof) );
+ }
+ else
+ {
+ // task is not running inside a thread-pool
+ // the sub-tasks are executed in new threads
+ h1 = boost::task::async(
+ boost::this_task::new_thread(),
+ tsk::make_task(
+ parallel_fib,
+ n - 1,
+ cutof) );
+ h2 = boost::task::async(
+ boost::this_task::new_thread(),
+ boost::task::make_task(
+ parallel_fib,
+ n - 2,
+ cutof) );
+ }
+ return h1.get() + h2.get();
+ }
+ }
+
+ void main()
+ {
+ boost::task::handle< long > h(
+ boost::task::async(
+ // boost::task::new_thread(),
+ boost::task::default_pool(),
+ boost::task::make_task(
+ parallel_fib,
+ 10,
+ 5) ) );
+ std::cout << h.get() << std::endl;
+ }
+};
+
[endsect]
Added: sandbox/task/libs/task/doc/overview.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/overview.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -0,0 +1,76 @@
+[/
+ Copyright Oliver Kowalke 2009.
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+]
+
+
+[section:overview Overview]
+
+[heading Description]
+
+__boost_task__ provides an abstraction for parallel execution of tasks - a task is a small unit of code that can be executed independently.
+
+* __task__, representing fine-grained work-item:
+ * get_id() returning an identifier
+ * operator() to execute the fine-grained work-item
+ * get_future() providing an __act__ in order to pass the result (values, exceptions) back to initiator
+
+* __handle__, __act__ of the asynchronously executed task:
+ * get_id() for identifying associated __task__
+ * interrupt(), interrupt_and_wait() allow to cancel an coop_task_link[cooperative task]
+ * interface of __act__:
+ * get() retrieve value or exception of task execution
+ * is_ready() test if task was executed
+ * wait(), wait_for() and wait_until() block until task is executed and the result is set
+
+* __async__, execute a task on behalf of __aes__
+
+* __ae__ models:
+ * __own_thread__: executes task in current thread.
+ * __new_thread__: executes task in a newly created thread (thread will be destroyed after)
+ * __default_pool__: task gets executed by a __worker_thread__ of the default __thread_pool__
+ * __as_sub_task__: executes task in newly created thread or in a pool depending on whether current task is already executed in a pool
+ * custom pool: task gets executed by a __worker_thread__ of a custom __thread_pool__
+
+
+References
+
+* N2185: Proposed Text for Parallel Task Execution [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2185.html] written by Peter Dimov.
+
+* N2276: Thread Pools and Futures [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2276.html] written by Anthony Williams.
+
+* N2802: A plea to reconsider detach-on-destruction for thread objects [http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2802.html] written by Hans-J. Boehm.
+
+* C++task-force mailing list
+
+[note __boost_task__ uses __boost_future__ from Anthony Williams (will be integrated in some of the next releases of __boost__thread__).]
+
+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/task.hpp>
+
+which includes all the other headers in turn.
+
+
+[heading Tested Platforms]
+__boost_task__ has been tested on the following platforms and compilers:
+
+* Linux 2.6.29.2 (amd64), GCC 4.3.2
+* Linux 2.6.23.9 (i386), GCC 4.2.4
+* FreeBSD 7.2 (amd64), GCC 4.2.1
+* OpenSolaris 0811 (amd64), GCC 4.2.1
+* Windows XP Professional (i386), MSVC 9.0
+
+
+[heading How to build]
+* define environment variable BOOST_SOURCE_ROOT pointing to the source directory of __boost__
+* extract archive of __boost_task__
+* call bjam in the directory of __boost_task__
+
+
+[include introduction.qbk]
+
+[endsect]
Added: sandbox/task/libs/task/doc/rationale.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/rationale.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -0,0 +1,23 @@
+[/
+ Copyright Oliver Kowalke 2009.
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+]
+
+
+[section:rationale Appendix A: Rationale]
+
+* task : because future does not catch std::exceptions, boost::thread_interrupted, boost::exception
+ support of task-id
+
+* pool : work-stealing and pre-forking of threads, inline execution of local tasks; scheduling
+ default pool with worker-threads as cores
+
+* this-task : functions useable inside tasks
+
+* handle : async completion token, task interruption, association with task via task-id
+
+* async : from mailing-list, execution of task in current thread, new thread in pool
+
+[endsect]
Deleted: sandbox/task/libs/task/doc/threadpool.qbk
==============================================================================
--- sandbox/task/libs/task/doc/threadpool.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
+++ (empty file)
@@ -1,59 +0,0 @@
-[/
- (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]
Deleted: sandbox/task/libs/task/doc/threadpool.xml
Added: sandbox/task/libs/task/doc/todo.qbk
Modified: sandbox/task/libs/task/examples/delay.cpp
Modified: sandbox/task/libs/task/examples/fork_join.cpp
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk
==============================================================================
--- sandbox/task/libs/task/doc/threadpool.xml 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
+++ (empty file)
@@ -1,3014 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
-<library id="boost_threadpool" name="Boost.Threadpool" dirname="boost_threadpool"
-last-revision="$Date: 2009/03/03 21:18:36 $" xmlns:xi="http://www.w3.org/2001/XInclude">
- <libraryinfo>
- <authorgroup>
- <author>
- <firstname>Oliver</firstname> <surname>Kowalke</surname>
- </author>
- </authorgroup>
- <copyright>
- <year>2008</year> <holder>Oliver Kowalke</holder>
- </copyright>
- <legalnotice>
- <para>
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at <ulink url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt>)
- </para>
- </legalnotice>
- <librarypurpose>
- C++ Library for executing actions in a pool of worker threads
- </librarypurpose>
- <librarycategory name="category:text"></librarycategory>
- </libraryinfo>
- <title>Boost.Threadpool</title>
- <section id="boost_threadpool.introduction">
- <title><link linkend="boost_threadpool.introduction">Introduction</link></title>
- <para>
- <emphasis role="bold">Boost.Threadpool</emphasis> is designed for effectively
- utilize the available hardware and provide a way for efficient asynchronous
- processing of independent time consuming operations (actions) in the same process.
- A thread pool contains a number of worker threads to perform actions in parallel,
- which are usually managed by a scheduler. If a worker thread completes its
- action, it will take the next action from the scheduler until all actions have
- been completed. The worker thread then sleeps until there are new actions available.
- Using a pool of worker threads over creating a new thread for each action may
- result in better performance and better system stability because the overhead
- for thread creation and destruction is negated.
- </para>
- <para>
- <emphasis role="bold">Boost.Threadpool</emphasis> uses a <link linkend="boost_threadpool.pool.work_stealing"><emphasis>work
- stealing</emphasis></link> algorithm and supports <link linkend="boost_threadpool.forkjoin"><emphasis>fork/join</emphasis></link>
- parallelism (recursively splitting of actions into sub-actions that are solved
- in parallel, waiting for them to complete, and then joining results).
- </para>
- <para>
- In order to use the classes and functions described here, you can either include
- the specific headers specified by the descriptions of each class or function,
- or include the master library header:
- </para>
-
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-</programlisting>
- <para>
- which includes all the other headers in turn.
- </para>
- <note>
- <para>
- <emphasis role="bold">Boost.Threadpool</emphasis> uses a modified version
- of the futures library, N2561 C++0x proposal, from Anthony Williams (<ulink
- url="http://www.justsoftwaresolutions.co.uk/threading/updated-implementation-of-c++-futures-3.html">http://www.justsoftwaresolutions.co.uk/threading/updated-implementation-of-c++-futures-3.html>).
- </para>
- </note>
- </section>
- <section id="boost_threadpool.pool">
- <title><link linkend="boost_threadpool.pool"> Pool</link></title>
- <para>
- The pool manages internaly worker threads and submitted actions are stored
- in a <link linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>
- (<link linkend="boost_threadpool.pool.work_stealing"><emphasis>global queue</emphasis></link>)
- for processing by the worker threads (using a <link linkend="boost_threadpool.pool.work_stealing"><emphasis>work
- stealing</emphasis></link> algorithm). Each submitted action gets associated
- with a <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
- object that will be returned. The <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
- object acts as a proxy for a result that is initially not known and gets evaluated
- later by a worker thread.
- </para>
- <anchor id="boost_threadpool.pool.work_stealing"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.pool.work_stealing">Work-Stealing</link>
- </bridgehead>
- <para>
- Traditional thread poola do not scale because they use a single global queue
- protected by a global lock. The frequency at which worker threads aquire the
- global lock becomes a limiting factor for the throughput if:
- </para>
- <itemizedlist>
- <listitem>
- the actions become smaller
- </listitem>
- <listitem>
- more processors are added
- </listitem>
- </itemizedlist>
- <para>
- A work-stealing algorithm can be used to solve this problem. It uses a special
- kind of queue which has two ends, and allows lock-free pushes and pops from
- the <emphasis>private end</emphasis> (accessed by the worker thread owning
- the queue), but requires synchronization from the <emphasis>public end</emphasis>
- (accessed by the other worker threads). Synchronization is necessary when the
- queue is sufficiently small that private and public operations could conflict.
- </para>
- <para>
- The pool contains one global queue (<link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link> or <link linkend="boost_threadpool.channel.unbounded_channel"><emphasis>unbounded
- channel</emphasis></link>) protected by a global lock and each worker thread
- has its own private worker queue. If work is enqueued by a worker thread the
- action is stored in the worker queue. If the work is enqueued by a application
- thread it goes into the global queue. When worker threads are looking for work,
- they have following search order:
- </para>
- <itemizedlist>
- <listitem>
- look into the private worker queue - actions can be dequeued without locks
- </listitem>
- <listitem>
- look in the global queue - locks are used for synchronization
- </listitem>
- <listitem>
- check other worker queues ('stealing' actions from private worker queues
- of other worker threads) - requires locks
- </listitem>
- </itemizedlist>
- <para>
- For a lot of recursively queued actions, the use of a worker queue per thread
- substantially reduces the synchronization necessary to complete the work. There
- are also fewer cache effects due to sharing of the global queue information.
- </para>
- <para>
- Operations on the private worker queue are executed in LIFO order and operations
- on worker queues of other worker threads in FIFO order (steals).
- </para>
- <itemizedlist>
- <listitem>
- There are chances that memory is still hot in the cache, if the actions are
- pushed in LIFO order into the private worker queue.
- </listitem>
- <listitem>
- If a worker thread steals work in FIFO order, increases the chances that
- a larger 'chunk' of work will be stolen (the need for other steals will be
- possibly reduced). Because the actions are stored in LIFO order, the oldest
- items are closer to the <emphasis>public end</emphasis> of the queue (forming
- a tree). Stealing such an older action also steals a (probably) larger subtree
- of actions unfolded if the stolen work item get executed.
- </listitem>
- </itemizedlist>
- <note>
- <para>
- Actions submitted by a worker thread are stored into its private worker queue
- in LIFO order, thatswhy priorities and timeouts specified at the submit-function
- get ignored.
- </para>
- </note>
- <important>
- <para>
- Because of the work-stealing algorithm the execution order of actions may
- be not strict as in the global queue.
- </para>
- </important>
- <anchor id="boost_threadpool.pool.creation"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.pool.creation">Creation</link>
- </bridgehead>
- <para>
- The first template argument specifies the channel type and the scheduling policy.
- </para>
-
-<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">6</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">50</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">scanns</phrase><phrase role="special">(</phrase><phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-</programlisting>
- <para>
- In the example above a thread pool is created with a <link linkend="boost_threadpool.channel.unbounded_channel"><emphasis>unbounded
- channel</emphasis></link>, scheduling actions in <emphasis>FIFO</emphasis>
- order. The pool contains six worker threads going to sleep for 50 millisec
- after 10 iterations without geting an action from the <link linkend="boost_threadpool.pool.work_stealing"><emphasis>global
- queue</emphasis></link>, from its local <link linkend="boost_threadpool.pool.work_stealing"><emphasis>worker
- queue</emphasis></link> or local queues of other worker threads.
- </para>
-
-<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">bounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">priority</phrase> <phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">high_watermark</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">low_watermark</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-</programlisting>
- <para>
- This pool uses a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link> which schedules actions by integer atrributes. A
- maximum of 10 actions can be queued in the <link linkend="boost_threadpool.pool.work_stealing"><emphasis>global
- queue</emphasis></link> without blocking the inserting thread.
- </para>
- <anchor id="boost_threadpool.pool.shutdown"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.pool.shutdown">Shutdown</link>
- </bridgehead>
- <para>
- If <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">Channel</phrase> <phrase
- role="special">>::</phrase><phrase role="identifier">shutdown</phrase><phrase
- role="special">()</phrase></code> is called - the the status of the pool is
- set to <emphasis>terminating</emphasis> and all worker threads are joined.
- No futher actions can be submitted by application threads. After all pending
- actions are processed and all worker threads are joined, the pool is set to
- status <emphasis>terminated</emphasis>.
- </para>
- <note>
- <para>
- The deconstructor calls <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase
- role="identifier">Channel</phrase> <phrase role="special">>::</phrase><phrase
- role="identifier">shutdown</phrase><phrase role="special">()</phrase></code>
- if the pool was not shutdown yet.
- </para>
- </note>
-
-<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase>
- <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase>
- <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">shutdown</phrase><phrase role="special">();</phrase>
-
-<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// 55
-</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// 55
-</phrase></programlisting>
- <anchor id="boost_threadpool.pool.shutdown_immediatly"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.pool.shutdown_immediatly">Shutdown immediatly</link>
- </bridgehead>
- <para>
- The function <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">Channel</phrase> <phrase
- role="special">>::</phrase><phrase role="identifier">shutdown_now</phrase><phrase
- role="special">()</phrase></code> sets the pool status to <emphasis>terminating</emphasis>
- interrupts and then joins all worker threads. After the worker threads are
- joined the status of the pool is set to <emphasis>terminated</emphasis> and
- all pending (unprocessed) actions will be returned.
- </para>
- <important>
- <para>
- Pending actions in the local <link linkend="boost_threadpool.pool.work_stealing"><emphasis>worker
- queues</emphasis></link> are not returned if <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase
- role="identifier">Channel</phrase> <phrase role="special">>::</phrase><phrase
- role="identifier">shutdown_now</phrase><phrase role="special">()</phrase></code>
- was called.
- </para>
- </important>
- <anchor id="boost_threadpool.pool.default_pool"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.pool.default_pool">Default pool</link>
- </bridgehead>
- <para>
- The free function <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">get_default_pool</phrase><phrase
- role="special">()</phrase></code> returns a reference to the default thread
- pool instance. The default thread pool is of type <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase
- role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase
- role="special">></phrase></code> and will contain as many worker threads
- as <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
- role="identifier">hardware_concurrency</phrase><phrase role="special">()</phrase></code>
- returns.
- </para>
- <anchor id="boost_threadpool.pool.meta_functions"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.pool.meta_functions">Meta functions</link>
- </bridgehead>
- <para>
- If the thread pool supports priorities <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">has_priority</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="special">></phrase></code>
- evaluates to <code><phrase role="keyword">true</phrase></code>. The priority
- type is determined by <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">priority_type</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="special">></phrase></code>.
- </para>
-
-<programlisting><phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">priority</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
-
-<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">has_priority</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>::</phrase><phrase role="identifier">value</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="keyword">typeid</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">priority_type</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase><phrase role="special">).</phrase><phrase role="identifier">name</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-</programlisting>
- <para>
- The support of fibers can be tested with meta-function <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">has_fibers</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="special">></phrase></code>.
- </para>
-
-<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">has_fibers</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>::</phrase><phrase role="identifier">value</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-</programlisting>
- <anchor id="boost_threadpool.pool.processor_binding"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.pool.processor_binding">Processor binding</link>
- </bridgehead>
- <para>
- For some applications it is convenient to bind the worker threads of the pool
- to processors of the system. For this purpose BOOST_BIND_WORKER_TO_PROCESSORS
- must be defined. Without the poolsize in the construtor the thread pool will
- contain as many worker threads as processors (== boost::thread::hardware_concurrency)
- are available and each worker thread is bound to one processor.
- </para>
-
-<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
- <phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">;</phrase>
-</programlisting>
- <para>
- The code above will create a pool with two worker threads on a dual core system
- (each bound to one core).
- </para>
- </section>
- <section id="boost_threadpool.task">
- <title><link linkend="boost_threadpool.task"> Task</link></title>
- <para>
- For each submitted action a new task object will be created and returned by
- the pool. The <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
- object acts as a proxy for a result that is initially not known and gets evaluated
- later by a worker thread. It transports the result (value or exception) of
- the action back to the caller.
- </para>
-
-<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="comment">// task calculates fibonacci(10)
-</phrase><phrase role="comment">// scheduled in unbounded channel with FIFO ordering
-</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
-<phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase>
- <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// 55
-</phrase></programlisting>
- <anchor id="boost_threadpool.task.interruption"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.task.interruption">Interruption</link>
- </bridgehead>
- <para>
- The returned <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
- object provides the possiblity to interrupt an action if it is cooperative.
- An action is known as cooperative if it includes interruption points in its
- code:
- </para>
- <itemizedlist>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
- role="identifier">join</phrase><phrase role="special">()</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
- role="identifier">timed_join</phrase><phrase role="special">()</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">condition_variable</phrase><phrase role="special">::</phrase><phrase
- role="identifier">wait</phrase><phrase role="special">()</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">condition_variable</phrase><phrase role="special">::</phrase><phrase
- role="identifier">timed_wait</phrase><phrase role="special">()</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">condition_variable_any</phrase><phrase role="special">::</phrase><phrase
- role="identifier">wait</phrase><phrase role="special">()</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">condition_variable_any</phrase><phrase role="special">::</phrase><phrase
- role="identifier">timed_wait</phrase><phrase role="special">()</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
- role="identifier">sleep</phrase><phrase role="special">()</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">this_thread</phrase><phrase role="special">::</phrase><phrase
- role="identifier">sleep</phrase><phrase role="special">()</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">this_thread</phrase><phrase role="special">::</phrase><phrase
- role="identifier">interruption_point</phrase><phrase role="special">()</phrase></code>
- </listitem>
- </itemizedlist>
- <important>
- <para>
- Interruption must not be disabled for the worker thread (class <emphasis>boost::this_thread::disable_interruption</emphasis>).
- </para>
- </important>
- <para>
- The action will be interrupted even if it is pending (interruption is remembered).
- A <emphasis>boost::thread_interrupted</emphasis> exception will be thrown by
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">T</phrase> <phrase role="special">>::</phrase><phrase
- role="identifier">get</phrase><phrase role="special">()</phrase></code> if
- the action was interrupted.
-<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="comment">// submit a long running task
-</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">long_running_fn</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="comment">// interrupt task
-</phrase><phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">interrupt</phrase><phrase role="special">();</phrase>
-
-<phrase role="comment">// throws boost::thread_interrupted exception
-</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-</programlisting>
- </para>
-
-<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="comment">// submit a long running task
-</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">long_running_fn</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="comment">// interrupt task and wait for its termination
-</phrase><phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">();</phrase>
-
-<phrase role="comment">// throws boost::thread_interrupted exception
-</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-</programlisting>
- <anchor id="boost_threadpool.task.exceptions_in_tasks"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.task.exceptions_in_tasks">Exceptions in tasks</link>
- </bridgehead>
- <para>
- Exceptions thrown inside an action are transported by the associated task object.
- Exceptions rethrown by type:
- </para>
- <itemizedlist>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">bad_alloc</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">bad_cast</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">bad_exception</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">bad_typeid</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">domain_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_argument</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">ios_base</phrase><phrase role="special">::</phrase><phrase
- role="identifier">failure</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">length_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">logic_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">out_of_range</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">overflow_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">range_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">runtime_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">underflow_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">broken_promise</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">future_already_set</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">future_cancel</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_thread_argument</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">lock_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">thread_exception</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">thread_interrupted</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">thread_permission_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">thread_resource_error</phrase></code>
- </listitem>
- <listitem>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">unsupported_thread_option</phrase></code>
- </listitem>
- </itemizedlist>
- <para>
- Exceptions derived from <code><phrase role="identifier">std</phrase><phrase
- role="special">::</phrase><phrase role="identifier">exception</phrase></code>
- will be rethrown as <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
- role="identifier">runtime_error</phrase></code> in all other cases a <code><phrase
- role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bad_exception</phrase></code>
- is thrown.
- </para>
-
-<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="comment">// task will throw an exception derived from std::exception
-</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">throwing_fn</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">t</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// will rethrow an std::runtime_error
-</phrase></programlisting>
- </section>
- <section id="boost_threadpool.this_task">
- <title><link linkend="boost_threadpool.this_task"> Namespace this_task</link></title>
- <para>
- In the function <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase
- role="identifier">reschedule_until</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">shared_future</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">R</phrase> <phrase role="special">></phrase>
- <phrase role="keyword">const</phrase><phrase role="special">&)</phrase></code>
- allows to synchronize the task with other asynchronous events without blocking
- the worker threads. The current task will be rescheduled until the passed future
- becomes ready. The pool can be accessed via <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase
- role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">Pool</phrase> <phrase
- role="special">>()</phrase></code> if the calling code is executed by a
- worker thread.
- </para>
- </section>
- <section id="boost_threadpool.channel">
- <title><link linkend="boost_threadpool.channel"> Channel</link></title>
- <para>
- The channel synchronizes the access between application threads (producer threads)
- submitting actions to the pool and worker threads (consumer threads). The scheduling
- of actions queued into the channel depends on channels the scheduling policy.
- If the channel becomes empty all worker threads are set to sleep until a new
- action is put in.
- </para>
- <anchor id="boost_threadpool.channel.bounded_channel"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.channel.bounded_channel">bounded channel</link>
- </bridgehead>
-
-<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">SchedulingPolicy</phrase> <phrase role="special">></phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">bounded_channel</phrase>
-</programlisting>
- <para>
- The number of pending actions is limited in order to prevent resource exhaustion.
- For this purpose a high and low watermark has to be passed at construction.
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">high_watermark</phrase></code>
- sets the maximum of pending tasks. If this limited is reached all threads which
- submit a tasks will be set to sleep (blocked). <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">low_watermark</phrase></code> sets the threshold when blocked
- threads get woken up. If high watermark is equal to low watermark everytime
- a sleeping producer thread will be woken up and puts its task if one worker
- thread has taken a task from the channel. If low watermark is less than high
- watermark all sleeping producer threads will be woken up if the amount of pending
- tasks reaches low watermark.
- </para>
- <anchor id="boost_threadpool.channel.unbounded_channel"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.channel.unbounded_channel">unbounded channel</link>
- </bridgehead>
-
-<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">SchedulingPolicy</phrase> <phrase role="special">></phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">unbounded_channel</phrase>
-</programlisting>
- <para>
- An unlimited number of actions can be queued into this channel. The insertion
- of actions will never block. If the channel becomes empty worker threads will
- be set to sleep until new actions are inserted into the channel.
- </para>
- </section>
- <section id="boost_threadpool.scheduling">
- <title><link linkend="boost_threadpool.scheduling"> Scheduling</link></title>
- <para>
- The scheduling policy determines how actions are scheduled inside the <link
- linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>.
- </para>
- <anchor id="boost_threadpool.scheduling.fifo"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.scheduling.fifo">fifo</link>
- </bridgehead>
-
-<programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">fifo</phrase>
-</programlisting>
- <para>
- First inserted pending action get taken first.
- </para>
- <anchor id="boost_threadpool.scheduling.lifo"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.scheduling.lifo">lifo</link>
- </bridgehead>
-
-<programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">lifo</phrase>
-</programlisting>
- <para>
- Last inserted pending action get taken first.
- </para>
- <anchor id="boost_threadpool.scheduling.priority"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.scheduling.priority">priority</link>
- </bridgehead>
-
-<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Ord</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">less</phrase><phrase role="special"><</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="keyword">struct</phrase> <phrase role="identifier">priority</phrase>
-</programlisting>
- <para>
- Each pending task is associated with a priority attribute which is used for
- ordering actions.
- </para>
- <anchor id="boost_threadpool.scheduling.smart"/>
- <bridgehead renderas="sect3">
- <link linkend="boost_threadpool.scheduling.smart">smart</link>
- </bridgehead>
-
-<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Ord</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Enq</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Deq</phrase> <phrase role="special">></phrase> <phrase role="keyword">struct</phrase> <phrase role="identifier">smart</phrase>
-</programlisting>
- <para>
- Each pending actions is associated with an attribute. The scheduler gets an
- put- and take-policy as template arguments. The corresponding policy get applied
- for each insertion and removal.
- </para>
- <para>
- <emphasis role="bold">Boost.Threadpool</emphasis> provides <emphasis>boost::tp::replace_oldest</emphasis>
- as put policy and <emphasis>boost::tp::take_oldest</emphasis> as take policy.
- Both policies allow the replacement of old actions in the scheduler by new
- ones.
- </para>
-
-<programlisting><phrase role="comment">// creates a pool with unbounded channel
-</phrase><phrase role="comment">// tasks are processed depending on the associated attributed
-</phrase><phrase role="comment">// oldest tasks with the same attributed pending in the channel
-</phrase><phrase role="comment">// will be replaced by the new task
-</phrase><phrase role="comment">// this example would execute add( 1, 2) and add( 5, 6)
-</phrase><phrase role="comment">// add( 2, 3) is removed (if pending when add( 5, 6) is submitted)
-</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">smart</phrase><phrase role="special"><</phrase>
- <phrase role="keyword">int</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">less</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">>,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">replace_oldest</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">take_oldest</phrase>
- <phrase role="special">></phrase>
- <phrase role="special">></phrase>
-<phrase role="special">></phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-<phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">add_fn</phrase><phrase role="special">,</phrase>
- <phrase role="number">1</phrase><phrase role="special">,</phrase>
- <phrase role="number">2</phrase><phrase role="special">),</phrase>
- <phrase role="number">0</phrase><phrase role="special">);</phrase>
-
-<phrase role="comment">// replaced by later task with same attribute
-</phrase><phrase role="comment">// if still pending in pool
-</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">add_fn</phrase><phrase role="special">,</phrase>
- <phrase role="number">3</phrase><phrase role="special">,</phrase>
- <phrase role="number">4</phrase><phrase role="special">),</phrase>
- <phrase role="number">1</phrase><phrase role="special">);</phrase>
-
-<phrase role="comment">// will replace previous pending action
-</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">add_fn</phrase><phrase role="special">,</phrase>
- <phrase role="number">5</phrase><phrase role="special">,</phrase>
- <phrase role="number">6</phrase><phrase role="special">),</phrase>
- <phrase role="number">1</phrase><phrase role="special">);</phrase>
-</programlisting>
- </section>
- <section id="boost_threadpool.forkjoin">
- <title><link linkend="boost_threadpool.forkjoin"> Fork/Join</link></title>
- <para>
- Fork/Join algorithms are recursive divide-and-conquer algorithms which repeatedly
- splitt sub_actions until they become small enough to solve using simple, short
- sequential methods, so that they run in parallel on multiple cores.
- </para>
- <para>
- The fork operation creates a new sub_action (which can run in parallel) in
- the pool. The current actions is not proceeded in the join operation until
- the forked sub_actions have completed. In the meantime the worker thread executes
- other actions from its local <link linkend="boost_threadpool.pool.work_stealing"><emphasis>worker
- queue</emphasis></link>.
- </para>
-
-<programlisting> <phrase role="comment">// defines the threadpool type
-</phrase> <phrase role="keyword">namespace</phrase> <phrase role="identifier">pt</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">posix_time</phrase><phrase role="special">;</phrase>
-<phrase role="keyword">namespace</phrase> <phrase role="identifier">tp</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">;</phrase>
-
-<phrase role="keyword">typedef</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">fibo</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">private</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
- <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
- <phrase role="special">}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
- <phrase role="keyword">else</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
- <phrase role="special">}</phrase>
- <phrase role="special">}</phrase>
-
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">{}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
-<phrase role="special">};</phrase>
-
-<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">try</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- // defines the threadpool type namespace pt = boost::posix_time; namespace
- tp = boost::tp;
- </para>
-
-<programlisting><phrase role="keyword">typedef</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">fibo</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">private</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
- <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
- <phrase role="special">}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
- <phrase role="keyword">else</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
- <phrase role="special">}</phrase>
- <phrase role="special">}</phrase>
-
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">{}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
-<phrase role="special">};</phrase>
-
-<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">try</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- typedef tp::pool< tp::unbounded_channel< tp::fifo > > pool_type;
- </para>
-
-<programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">fibo</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">private</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
- <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
- <phrase role="special">}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
- <phrase role="keyword">else</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
- <phrase role="special">}</phrase>
- <phrase role="special">}</phrase>
-
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">{}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
-<phrase role="special">};</phrase>
-
-<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">try</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- class fibo { private: int offset_;
- </para>
-
-<programlisting> <phrase role="keyword">int</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
- <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
- <phrase role="special">}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
- <phrase role="keyword">else</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
- <phrase role="special">}</phrase>
- <phrase role="special">}</phrase>
-
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">{}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
-<phrase role="special">};</phrase>
-
-<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">try</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- int seq<emphasis role="underline">( int n) { if ( n <= 1) return n; else
- return seq</emphasis>( n - 2) + seq_( n - 1); }
- </para>
-
-<programlisting> <phrase role="keyword">int</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special"><=</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">seq_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
- <phrase role="keyword">else</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t1</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="identifier">t2</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase role="identifier">get_thread_pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">>().</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">par_</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="special">*</phrase> <phrase role="keyword">this</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">t1</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">t2</phrase><phrase role="special">.</phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">();</phrase>
- <phrase role="special">}</phrase>
- <phrase role="special">}</phrase>
-
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">{}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
-<phrase role="special">};</phrase>
-
-<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">try</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- int par<emphasis role="underline">( int n) { if ( n <= offset</emphasis>)
- return seq_( n); else { tp::task< int > t1( boost::this_task::get_thread_pool<
- pool<emphasis role="underline">type >().submit( boost::bind( & fibo::par</emphasis>,
- boost::ref( * this), n - 1) ) ); tp::task< int > t2( boost::this_task::get_thread_pool<
- pool<emphasis role="underline">type >().submit( boost::bind( & fibo::par</emphasis>,
- boost::ref( * this), n - 2) ) ); return t1.result().get() + t2.result().get();
- } }
- </para>
-
-<programlisting><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">fibo</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">:</phrase> <phrase role="identifier">offset_</phrase><phrase role="special">(</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase>
- <phrase role="special">{}</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
-<phrase role="special">};</phrase>
-
-<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">try</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- public: fibo( int offset) : offset_( offset) {}
- </para>
-
-<programlisting> <phrase role="keyword">int</phrase> <phrase role="identifier">execute</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">(</phrase> <phrase role="identifier">par_</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
-<phrase role="special">};</phrase>
-
-<phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">try</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- int execute( int n) { int result( par_( n) ); return result; } };
- </para>
-
-<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">argc</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="special">*</phrase><phrase role="identifier">argv</phrase><phrase role="special">[])</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">try</phrase>
- <phrase role="special">{</phrase>
- <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">3</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">fibo</phrase> <phrase role="identifier">fib</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="identifier">results</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase> <phrase role="number">40</phrase><phrase role="special">);</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- int main( int argc, char *argv[]) { try { pool_type pool( tp::poolsize( 3)
- ); fibo fib( 5); std::vector< tp::task< int > > results; results.reserve(
- 40);
- </para>
-
-<programlisting> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">start</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- pt::ptime start( pt::microsec_clock::universal_time() );
- </para>
-
-<programlisting> <phrase role="keyword">for</phrase> <phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special"><</phrase> <phrase role="number">32</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
- <phrase role="special">&</phrase> <phrase role="identifier">fibo</phrase><phrase role="special">::</phrase><phrase role="identifier">execute</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase> <phrase role="identifier">fib</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- for ( int i = 0; i < 32; ++i) results.push_back( pool.submit( boost::bind(
- & fibo::execute, boost::ref( fib), i) ) );
- </para>
-
-<programlisting> <phrase role="keyword">int</phrase> <phrase role="identifier">k</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">e</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="keyword">for</phrase> <phrase role="special">(</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">int</phrase> <phrase role="special">></phrase> <phrase role="special">>::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase><phrase role="special">(</phrase> <phrase role="identifier">results</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">e</phrase><phrase role="special">;</phrase>
- <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="string">"fibonacci "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">k</phrase><phrase role="special">++</phrase> <phrase role="special"><<</phrase> <phrase role="string">" == "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">i</phrase><phrase role="special">-></phrase><phrase role="identifier">result</phrase><phrase role="special">().</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- int k = 0; std::vector< tp::task< int > >::iterator e( results.end()
- ); for ( std::vector< tp::task< int > >::iterator i( results.begin()
- ); i != e; ++i) std::cout << "fibonacci " << k++ <<
- " == " << i->result().get() << std::endl;
- </para>
-
-<programlisting> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">ptime</phrase> <phrase role="identifier">stop</phrase><phrase role="special">(</phrase> <phrase role="identifier">pt</phrase><phrase role="special">::</phrase><phrase role="identifier">microsec_clock</phrase><phrase role="special">::</phrase><phrase role="identifier">universal_time</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special"><<</phrase> <phrase role="special">(</phrase> <phrase role="identifier">stop</phrase> <phrase role="special">-</phrase> <phrase role="identifier">start</phrase><phrase role="special">).</phrase><phrase role="identifier">total_milliseconds</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="string">" milli seconds"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- pt::ptime stop( pt::microsec_clock::universal_time() ); std::cout <<
- ( stop - start).total_milliseconds() << " milli seconds" <<
- std::endl;
- </para>
-
-<programlisting> <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_SUCCESS</phrase><phrase role="special">;</phrase>
- <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">e</phrase><phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"exception: "</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">e</phrase><phrase role="special">.</phrase><phrase role="identifier">what</phrase><phrase role="special">()</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
- <phrase role="keyword">catch</phrase> <phrase role="special">(</phrase> <phrase role="special">...</phrase> <phrase role="special">)</phrase>
- <phrase role="special">{</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase> <phrase role="special"><<</phrase> <phrase role="string">"unhandled"</phrase> <phrase role="special"><<</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
-
- <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr <<
- "exception: " << e.what() << std::endl; } catch ( ...
- ) { std::cerr << "unhandled" << std::endl; }
- </para>
-
-<programlisting> <phrase role="keyword">return</phrase> <phrase role="identifier">EXIT_FAILURE</phrase><phrase role="special">;</phrase>
-<phrase role="special">}</phrase>
-</programlisting>
- <para>
- return EXIT_FAILURE; }
- </para>
- </section>
- <section id="boost_threadpool.acknowledgement">
- <title><link linkend="boost_threadpool.acknowledgement"> Acknowledgements</link></title>
- <para>
- I'd like to thank Vincente Botet Escriba for his comments on the implementation
- details of the code and Anthony Williams and Braddock Gaskill for their future
- libraries.
- </para>
- </section>
- <section id="boost_threadpool.reference">
- <title><link linkend="boost_threadpool.reference"> Reference</link></title>
- <section id="boost_threadpool.reference.pool">
- <title><link linkend="boost_threadpool.reference.pool"> Class template <code><phrase
- role="identifier">pool</phrase></code></link></title>
-<programlisting> <phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
- <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Channel</phrase> <phrase role="special">></phrase>
- <phrase role="keyword">class</phrase> <phrase role="identifier">pool</phrase>
- <phrase role="special">:</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">noncopyable</phrase>
- <phrase role="special">{</phrase>
- <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
-
- <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-
- <phrase role="special">~</phrase><phrase role="identifier">pool</phrase><phrase role="special">();</phrase>
-
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">();</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">active</phrase><phrase role="special">();</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">idle</phrase><phrase role="special">();</phrase>
-
- <phrase role="keyword">void</phrase> <phrase role="identifier">shutdown</phrase><phrase role="special">();</phrase>
- <phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">callable</phrase> <phrase role="special">></phrase> <phrase role="identifier">shutdown_now</phrase><phrase role="special">();</phrase>
-
- <phrase role="keyword">bool</phrase> <phrase role="identifier">terminated</phrase><phrase role="special">();</phrase>
- <phrase role="keyword">bool</phrase> <phrase role="identifier">terminateing</phrase><phrase role="special">();</phrase>
- <phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">();</phrase>
- <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
- <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">pending</phrase><phrase role="special">();</phrase>
-
- <phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">();</phrase>
- <phrase role="keyword">void</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">);</phrase>
- <phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">();</phrase>
- <phrase role="keyword">void</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">);</phrase>
-
- <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase> <phrase role="special">></phrase>
- <phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special"><</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase> <phrase role="special">></phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">act</phrase><phrase role="special">);</phrase>
-
- <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">></phrase>
- <phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special"><</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase> <phrase role="special">></phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">act</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">Attr</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">attr</phrase><phrase role="special">);</phrase>
- <phrase role="special">};</phrase>
-
-<phrase role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="special">&</phrase> <phrase role="identifier">get_default_pool</phrase><phrase role="special">();</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.pool.constructor_unbounded_channel_hw">
- <title><link linkend="boost_threadpool.reference.pool.constructor_unbounded_channel_hw">
- Constructor (unbounded channel)</link></title>
-<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- Operating system provides functionality for processor pining.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">Channel</phrase>
- <phrase role="special">></phrase></code> instance. For each processor
- a worker-thread is created and each worker-thread is pined exactly
- to one processor.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_scanns</phrase></code>, <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Constructor has to be called if a <link linkend="boost_threadpool.channel.unbounded_channel"><emphasis>unbounded
- channel</emphasis></link> is used.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.constructor_unbounded_channel">
- <title><link linkend="boost_threadpool.reference.pool.constructor_unbounded_channel">
- Constructor (unbounded channel)</link></title>
-<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">Channel</phrase>
- <phrase role="special">></phrase></code> instance. Pool contains
- psize worker-threads.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_scanns</phrase></code>, <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Constructor has to be called if a <link linkend="boost_threadpool.channel.unbounded_channel"><emphasis>unbounded
- channel</emphasis></link> is used.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.constructor_bounded_channel_hw">
- <title><link linkend="boost_threadpool.reference.pool.constructor_bounded_channel_hw">
- Constructor (bounded channel)</link></title>
-<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- Operating system provides functionality for processor pining.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">Channel</phrase>
- <phrase role="special">></phrase></code> instance. For each processor
- a worker-thread is created and each worker-thread is pined exactly
- to one processor.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_scanns</phrase></code>, <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>,
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_watermark</phrase></code>
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Constructor has to be called if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link> is used.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.constructor_bounded_channel">
- <title><link linkend="boost_threadpool.reference.pool.constructor_bounded_channel">
- Constructor (bounded channel)</link></title>
-<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
- <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">pool</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">Channel</phrase>
- <phrase role="special">></phrase></code> instance. Pool contains
- psize worker-threads.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_scanns</phrase></code>, <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>,
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_watermark</phrase></code>
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Constructor has to be called if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link> is used.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.destructor">
- <title><link linkend="boost_threadpool.reference.pool.destructor"> Destructor</link></title>
-
-<programlisting><phrase role="special">~</phrase><phrase role="identifier">pool</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Calls <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">pool</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">Channel</phrase> <phrase role="special">>::</phrase><phrase
- role="identifier">shutdown</phrase><phrase role="special">()</phrase></code>
- if not yet called.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.size">
- <title><link linkend="boost_threadpool.reference.pool.size"> Member function
- <code><phrase role="identifier">size</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">size</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns how many worker threads are running in the pool.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.active">
- <title><link linkend="boost_threadpool.reference.pool.active"> Member function
- <code><phrase role="identifier">active</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">active</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns how many worker threads are active (executing an action).
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.idle">
- <title><link linkend="boost_threadpool.reference.pool.idle"> Member function
- <code><phrase role="identifier">idle</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">idle</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns how many worker threads are idle (not executing an action).
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- The value is the difference of <code><phrase role="identifier">size</phrase><phrase
- role="special">()</phrase></code> and <code><phrase role="identifier">active</phrase><phrase
- role="special">()</phrase></code>
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.shutdown">
- <title><link linkend="boost_threadpool.reference.pool.shutdown"> Member function
- <code><phrase role="identifier">shutdown</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">shutdown</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Changes the pool state to <emphasis>terminating</emphasis>, deactivates
- the channel and joins all worker threads. The status of the pool is
- assigned to <emphasis>terminated</emphasis> at the end.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- All pending actions are processed.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.shutdown_now">
- <title><link linkend="boost_threadpool.reference.pool.shutdown_now"> Member
- function <code><phrase role="identifier">shutdown_now</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special"><</phrase> <phrase role="identifier">callable</phrase> <phrase role="special">></phrase> <phrase role="identifier">shutdown_now</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Changes the pool state to <emphasis>terminating</emphasis>, deactivates
- the channel, send interruption request to all worker threads and joins
- them. The status of the pool is assigned to <emphasis>terminated</emphasis>
- at the end.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Pending actions are not processed but returned.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.terminated">
- <title><link linkend="boost_threadpool.reference.pool.terminated"> Member
- function <code><phrase role="identifier">terminated</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">terminated</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Queries if the pool is in the terminated state (pool is shutdown).
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.terminateing">
- <title><link linkend="boost_threadpool.reference.pool.terminateing"> Member
- function <code><phrase role="identifier">terminateing</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">terminateing</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Queries if the pool is in the terminating state (tries to shutdown
- the pool).
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.clear">
- <title><link linkend="boost_threadpool.reference.pool.clear"> Member function
- <code><phrase role="identifier">clear</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Removes all pending actions from the <link linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.empty">
- <title><link linkend="boost_threadpool.reference.pool.empty"> Member function
- <code><phrase role="identifier">empty</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Queries if the <link linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>
- is empty.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.pending">
- <title><link linkend="boost_threadpool.reference.pool.pending"> Member function
- <code><phrase role="identifier">pending</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">pending</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Queries how many actions are pending in the <link linkend="boost_threadpool.channel"><emphasis>channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.get_upper_bound">
- <title><link linkend="boost_threadpool.reference.pool.get_upper_bound"> Member
- function <code><phrase role="identifier">upper_bound</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- Channel is of type <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns the upper bound of the <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Can only be used if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link> is used.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.set_upper_bound">
- <title><link linkend="boost_threadpool.reference.pool.set_upper_bound"> Member
- function <code><phrase role="identifier">upper_bound</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase
- role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase
- role="special">)</phrase></code></link></title>
-<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- Channel is of type <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Sets the upper bound of the <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Postconditions:</term>
- <listitem>
- <para>
- <code><phrase role="keyword">this</phrase><phrase role="special">-></phrase><phrase
- role="identifier">upper_bound</phrase><phrase role="special">()</phrase>
- <phrase role="special">==</phrase> <phrase role="identifier">hwm</phrase></code>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_watermark</phrase></code>
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Can only be used if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link> is used.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.get_lower_bound">
- <title><link linkend="boost_threadpool.reference.pool.get_lower_bound"> Member
- function <code><phrase role="identifier">lower_bound</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- Channel is of type <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns the lower bound of the <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Can only be used if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link> is used.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.set_lower_bound">
- <title><link linkend="boost_threadpool.reference.pool.set_lower_bound"> Member
- function <code><phrase role="identifier">lower_bound</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase
- role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase
- role="special">)</phrase></code></link></title>
-<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- Channel is of type <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Sets the lower bound of the <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Postconditions:</term>
- <listitem>
- <para>
- <code><phrase role="keyword">this</phrase><phrase role="special">-></phrase><phrase
- role="identifier">lower_bound</phrase><phrase role="special">()</phrase>
- <phrase role="special">==</phrase> <phrase role="identifier">lwm</phrase></code>.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_watermark</phrase></code>
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- Can only be used if a <link linkend="boost_threadpool.channel.bounded_channel"><emphasis>bounded
- channel</emphasis></link> is used.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.submit">
- <title><link linkend="boost_threadpool.reference.pool.submit"> Member function
- <code><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase
- role="special">&</phrase> <phrase role="identifier">act</phrase><phrase
- role="special">)</phrase></code></link></title>
-<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase> <phrase role="special">></phrase>
-<phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special"><</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase> <phrase role="special">></phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">act</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- has_priority< pool >::value == false && ! ( pool.terminating()
- || pool.terminated() )
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Submits an action to the pool and returns a <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
- object.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">task_rejected</phrase></code>
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.submit_attr">
- <title><link linkend="boost_threadpool.reference.pool.submit_attr"> Member
- function <code><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase
- role="special">&</phrase> <phrase role="identifier">act</phrase><phrase
- role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase
- role="keyword">const</phrase><phrase role="special">&</phrase> <phrase
- role="identifier">attr</phrase><phrase role="special">)</phrase></code></link></title>
-
-<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Act</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">></phrase>
-<phrase role="identifier">task</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">result_of</phrase><phrase role="special"><</phrase> <phrase role="identifier">Act</phrase><phrase role="special">()</phrase> <phrase role="special">>::</phrase><phrase role="identifier">type</phrase> <phrase role="special">></phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">act</phrase><phrase role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">attr</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- has_priority< pool >::value == true && ! ( pool.terminating()
- || pool.terminated() )
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Submits an action to the pool and returns a <link linkend="boost_threadpool.task"><emphasis>task</emphasis></link>
- object. <emphasis role="underline">_Action</emphasis>_ is scheduled
- by the attribute.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">task_rejected</phrase></code>
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.pool.get_default_pool">
- <title><link linkend="boost_threadpool.reference.pool.get_default_pool">
- Non-member function <code><phrase role="identifier">get_default_pool</phrase><phrase
- role="special">()</phrase></code></link></title>
-<programlisting><phrase role="identifier">pool</phrase><phrase role="special"><</phrase> <phrase role="identifier">unbounded_channel</phrase><phrase role="special"><</phrase> <phrase role="identifier">fifo</phrase> <phrase role="special">></phrase> <phrase role="special">></phrase> <phrase role="special">&</phrase> <phrase role="identifier">get_default_pool</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Get access to default thread pool (static).
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.task">
- <title><link linkend="boost_threadpool.reference.task"> Class template <code><phrase
- role="identifier">task</phrase></code></link></title>
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase>
-<phrase role="keyword">class</phrase> <phrase role="identifier">task</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
- <phrase role="identifier">task</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">Pool</phrase> <phrase role="special">*</phrase> <phrase role="identifier">pool</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">fut</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">detail</phrase><phrase role="special">::</phrase><phrase role="identifier">interrupter</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">intr</phrase><phrase role="special">);</phrase>
-
- <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt</phrase><phrase role="special">();</phrase>
- <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">();</phrase>
- <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">(</phrase> <phrase role="identifier">system_time</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">);</phrase>
- <phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Duration</phrase> <phrase role="special">></phrase>
- <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">(</phrase> <phrase role="identifier">Duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">rel_time</phrase><phrase role="special">);</phrase>
- <phrase role="keyword">bool</phrase> <phrase role="identifier">interrupt_requested</phrase><phrase role="special">();</phrase>
-
- <phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="identifier">result</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.task.constructor">
- <title><link linkend="boost_threadpool.reference.task.constructor"> Constructor</link></title>
-
-<programlisting><phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
-<phrase role="identifier">task</phrase><phrase role="special">(</phrase>
- <phrase role="identifier">Pool</phrase> <phrase role="special">*</phrase> <phrase role="identifier">pool</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">fut</phrase><phrase role="special">,</phrase>
- <phrase role="identifier">detail</phrase><phrase role="special">::</phrase><phrase role="identifier">interrupter</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">intr</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">task</phrase><phrase
- role="special"><</phrase> <phrase role="identifier">R</phrase>
- <phrase role="special">></phrase></code> instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Notes:</term>
- <listitem>
- <para>
- task objects should only be constructed by the pool.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.task.interrupt">
- <title><link linkend="boost_threadpool.reference.task.interrupt"> Member
- function <code><phrase role="identifier">interrupt</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">interrupt</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Associated action will be interrupted the next time it enters a <link
- linkend="boost_threadpool.task.interruption"><emphasis>interruption
- point</emphasis></link> if interruption is not disabled. The function
- returns immediatly.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.task.interrupt_and_wait">
- <title><link linkend="boost_threadpool.reference.task.interrupt_and_wait">
- Member function <code><phrase role="identifier">interrupt_and_wait</phrase><phrase
- role="special">()</phrase></code></link></title>
-<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">();</phrase>
-
-<phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">(</phrase> <phrase role="identifier">system_time</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">);</phrase>
-
-<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">DurationTime</phrase> <phrase role="special">></phrase>
-<phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">(</phrase> <phrase role="identifier">DurationTime</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">rel_time</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Associated action will be interrupted the next time it enters one
- <link linkend="boost_threadpool.task.interruption"><emphasis>interruption
- point</emphasis></link> if interruption is not disabled. The function
- waits until the action has terminated or the specified duration td
- has elapsed.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.task.result">
- <title><link linkend="boost_threadpool.reference.task.result"> Member function
- <code><phrase role="identifier">result</phrase><phrase role="special">()</phrase></code></link></title>
-
-<programlisting><phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="identifier">result</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns fulfilled value or throws fulfilled exception via a shared_future.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">future</phrase><phrase role="special">::</phrase><phrase
- role="identifier">broken_promise</phrase></code>
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.reschedule_until">
- <title><link linkend="boost_threadpool.reference.reschedule_until"> Non-member
- function <code><phrase role="identifier">reschedule_until</phrase></code></link></title>
-
-<programlisting> <phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase>
-<phrase role="keyword">void</phrase> <phrase role="identifier">reschedule_until</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">unique_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="keyword">const</phrase><phrase role="special">&);</phrase>
-
-<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase>
-<phrase role="keyword">void</phrase> <phrase role="identifier">reschedule_until</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">shared_future</phrase><phrase role="special"><</phrase> <phrase role="identifier">R</phrase> <phrase role="special">></phrase> <phrase role="keyword">const</phrase><phrase role="special">&);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Reschedules current task until passed future becomes ready.
- </para>
- </listitem>
- <listitem>
- <para>
- [Throws:
- </para>
- </listitem>
- <listitem>
- <para>
- Nothing.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Note:</term>
- <listitem>
- <para>
- This function resides in namespace <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">this_task</phrase></code>.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.get_thread_pool">
- <title><link linkend="boost_threadpool.reference.get_thread_pool"> Non-member
- function <code><phrase role="identifier">get_thread_pool</phrase></code></link></title>
-
-<programlisting> <phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
-<phrase role="identifier">Pool</phrase> <phrase role="special">&</phrase> <phrase role="identifier">get_thread_pool</phrase><phrase role="special">();</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns reference to the thread pool where the current worker thread
- is running.
- </para>
- </listitem>
- <listitem>
- <para>
- [Throws:
- </para>
- </listitem>
- <listitem>
- <para>
- Nothing.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Note:</term>
- <listitem>
- <para>
- This function resides in namespace <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">this_task</phrase></code>.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.poolsize">
- <title><link linkend="boost_threadpool.reference.poolsize"> Class <code><phrase
- role="identifier">poolsize</phrase></code></link></title>
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">poolsize</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">explicit</phrase> <phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
-
- <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.poolsize.constructor">
- <title><link linkend="boost_threadpool.reference.poolsize.constructor"> Constructor</link></title>
-
-<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- value > 0
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">poolsize</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Postconditions:</term>
- <listitem>
- <para>
- operator std::size_t () > 0
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_poolsize</phrase></code>
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.poolsize.operator">
- <title><link linkend="boost_threadpool.reference.poolsize.operator"> Member
- function <code><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase
- role="special">::</phrase><phrase role="identifier">size_t</phrase><phrase
- role="special">()</phrase></code></link></title>
-<programlisting><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns pool size.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.scanns">
- <title><link linkend="boost_threadpool.reference.scanns"> Class <code><phrase
- role="identifier">scanns</phrase></code></link></title>
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">scanns</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">scanns</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">explicit</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
-
- <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.scanns.constructor">
- <title><link linkend="boost_threadpool.reference.scanns.constructor"> Constructor</link></title>
-
-<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Preconditions:</term>
- <listitem>
- <para>
- value >= 0
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">scanns</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Postconditions:</term>
- <listitem>
- <para>
- operator std::size_t () >= 0
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_scanns</phrase></code>
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.scanns.operator">
- <title><link linkend="boost_threadpool.reference.scanns.operator"> Member
- function <code><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase
- role="special">::</phrase><phrase role="identifier">size_t</phrase><phrase
- role="special">()</phrase></code></link></title>
-<programlisting><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns scanns size.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.high_watermark">
- <title><link linkend="boost_threadpool.reference.high_watermark"> Class <code><phrase
- role="identifier">high_watermark</phrase></code></link></title>
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">watermark</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">high_watermark</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">explicit</phrase> <phrase role="identifier">high_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
-
- <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.high_watermark.constructor">
- <title><link linkend="boost_threadpool.reference.high_watermark.constructor">
- Constructor</link></title>
-<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">high_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">high_watermark</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_watermark</phrase></code>
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.high_watermark.operator">
- <title><link linkend="boost_threadpool.reference.high_watermark.operator">
- Member function <code><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase
- role="special">::</phrase><phrase role="identifier">size_t</phrase><phrase
- role="special">()</phrase></code></link></title>
-<programlisting><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns high watermark.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.low_watermark">
- <title><link linkend="boost_threadpool.reference.low_watermark"> Class <code><phrase
- role="identifier">low_watermark</phrase></code></link></title>
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">watermark</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">low_watermark</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="keyword">explicit</phrase> <phrase role="identifier">low_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
-
- <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.low_watermark.constructor">
- <title><link linkend="boost_threadpool.reference.low_watermark.constructor">
- Constructor</link></title>
-<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">low_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">low_watermark</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
- role="identifier">tp</phrase><phrase role="special">::</phrase><phrase
- role="identifier">invalid_watermark</phrase></code>
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- <section id="boost_threadpool.reference.low_watermark.operator">
- <title><link linkend="boost_threadpool.reference.low_watermark.operator">
- Member function <code><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase
- role="special">::</phrase><phrase role="identifier">size_t</phrase><phrase
- role="special">()</phrase></code></link></title>
-<programlisting><phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Returns low watermark.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.invalid_poolsize">
- <title><link linkend="boost_threadpool.reference.invalid_poolsize"> Class
- <code><phrase role="identifier">invalid_poolsize</phrase></code></link></title>
-
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_poolsize</phrase>
-<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">invalid_poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.invalid_poolsize.constructor">
- <title><link linkend="boost_threadpool.reference.invalid_poolsize.constructor">
- Constructor</link></title>
-<programlisting><phrase role="identifier">invalid_poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">invalid_poolsize</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.invalid_scanns">
- <title><link linkend="boost_threadpool.reference.invalid_scanns"> Class <code><phrase
- role="identifier">invalid_scanns</phrase></code></link></title>
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_scanns</phrase>
-<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">invalid_scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.invalid_scanns.constructor">
- <title><link linkend="boost_threadpool.reference.invalid_scanns.constructor">
- Constructor</link></title>
-<programlisting><phrase role="identifier">invalid_scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">invalid_scanns</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.invalid_timeduration">
- <title><link linkend="boost_threadpool.reference.invalid_timeduration"> Class
- <code><phrase role="identifier">invalid_timeduration</phrase></code></link></title>
-
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_timeduration</phrase>
-<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">invalid_timeduration</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.invalid_timeduration.constructor">
- <title><link linkend="boost_threadpool.reference.invalid_timeduration.constructor">
- Constructor</link></title>
-<programlisting><phrase role="identifier">invalid_timeduration</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">invalid_timeduration</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.invalid_watermark">
- <title><link linkend="boost_threadpool.reference.invalid_watermark"> Class
- <code><phrase role="identifier">invalid_watermark</phrase></code></link></title>
-
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_watermark</phrase>
-<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">invalid_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.invalid_watermark.constructor">
- <title><link linkend="boost_threadpool.reference.invalid_watermark.constructor">
- Constructor</link></title>
-<programlisting><phrase role="identifier">invalid_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">invalid_watermark</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.task_rejected">
- <title><link linkend="boost_threadpool.reference.task_rejected"> Class <code><phrase
- role="identifier">task_rejected</phrase></code></link></title>
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">class</phrase> <phrase role="identifier">task_rejected</phrase>
-<phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">runtime_error</phrase>
-<phrase role="special">{</phrase>
-<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
- <phrase role="identifier">task_rejected</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- <section id="boost_threadpool.reference.task_rejected.constructor">
- <title><link linkend="boost_threadpool.reference.task_rejected.constructor">
- Constructor</link></title>
-<programlisting><phrase role="identifier">task_rejected</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
-</programlisting>
- <variablelist>
- <title></title> <varlistentry><term>Effects:</term>
- <listitem>
- <para>
- Constructs a <code><phrase role="identifier">boost</phrase><phrase
- role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
- role="special">::</phrase><phrase role="identifier">task_rejected</phrase></code>
- instance.
- </para>
- </listitem>
- </varlistentry> <varlistentry><term>Throws:</term>
- <listitem>
- <para>
- Nothing
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </section>
- </section>
- <section id="boost_threadpool.reference.has_priority">
- <title><link linkend="boost_threadpool.reference.has_priority"> Meta function
- <code><phrase role="identifier">has_priority</phrase></code></link></title>
-
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">info</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
-<phrase role="keyword">struct</phrase> <phrase role="identifier">has_priority</phrase>
-<phrase role="special">:</phrase>
-<phrase role="keyword">public</phrase> <phrase role="identifier">mpl</phrase><phrase role="special">::</phrase><phrase role="identifier">bool_</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">is_same</phrase><phrase role="special"><</phrase>
- <phrase role="identifier">detail</phrase><phrase role="special">::</phrase><phrase role="identifier">has_priority</phrase><phrase role="special">,</phrase>
- <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">::</phrase><phrase role="identifier">scheduler_type</phrase><phrase role="special">::</phrase><phrase role="identifier">priority_tag_type</phrase>
- <phrase role="special">>::</phrase><phrase role="identifier">value</phrase>
-<phrase role="special">></phrase>
-<phrase role="special">{};</phrase>
-</programlisting>
- </section>
- <section id="boost_threadpool.reference.priority_type">
- <title><link linkend="boost_threadpool.reference.priority_type"> Meta function
- <code><phrase role="identifier">priority_type</phrase></code></link></title>
-
-<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special"><</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">tp</phrase><phrase role="special">/</phrase><phrase role="identifier">info</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">></phrase>
-
-<phrase role="keyword">template</phrase><phrase role="special"><</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">></phrase>
-<phrase role="keyword">struct</phrase> <phrase role="identifier">priority_type</phrase>
-<phrase role="special">{</phrase>
- <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">::</phrase><phrase role="identifier">scheduler_type</phrase><phrase role="special">::</phrase><phrase role="identifier">attribute_type</phrase> <phrase role="identifier">type</phrase><phrase role="special">;</phrase>
-<phrase role="special">};</phrase>
-</programlisting>
- </section>
- </section>
-</library>
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/todo.qbk 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -0,0 +1,30 @@
+[/
+ Copyright Oliver Kowalke 2009.
+ Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt
+]
+
+
+[section:todo Appendix C: Future development]
+
+[heading Event variable]
+A event variable is a bivalued variable (up/down) on which a task can wait for an event to be set or reset. The calling task will be suspended until the state of the event variable is that required by the caller.
+
+[heading Buffer]
+A bounded/unbounded buffer is shared between several tasks. The data must be placed in, and retrieved from, the buffer under mutual exclusion.
+Condition synchronisation is required because a calling task attempting to place data into the buffer. Whne the buffer is full, must be suspended until there is space int the buffer. Also a retrieving task must be suspended when the buffer is empty. The data, once read, is destroyed.
+
+[heading Multicast]
+The data is sent to a specific group of tasks and all tasks in the group should receive the data. Only when all tasks have received one item of data then another item is allowed to be transmitted.
+
+[heading Rendezvous]
+A rendezvous uses direct naming and synchronous communication between tasks. One task that executes its command first will be delayed until the other tasks is ready to rendezvous.
+
+[heading Protected resource]
+A protected resource is a passive entity that controls access to the internal states (to the controled real resources).
+
+[heading Task groups]
+A task group defines a graph of inter-dependent tasks that can mostly be run in parallel. THe tasks in the group have dependencies or communicate with each other.
+
+[endsect]
==============================================================================
--- sandbox/task/libs/task/examples/delay.cpp (original)
+++ sandbox/task/libs/task/examples/delay.cpp 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -47,14 +47,14 @@
{
tsk::handle< long > h1(
tsk::async(
- tsk::default_pool(),
+ tsk::as_sub_task(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
n - 1) ) );
tsk::handle< long > h2(
tsk::async(
- tsk::default_pool(),
+ tsk::as_sub_task(),
tsk::make_task(
& fib_task::execute,
boost::ref( * this),
==============================================================================
--- sandbox/task/libs/task/examples/fork_join.cpp (original)
+++ sandbox/task/libs/task/examples/fork_join.cpp 2009-05-12 14:33:31 EDT (Tue, 12 May 2009)
@@ -27,45 +27,28 @@
return serial_fib( n - 1) + serial_fib( n - 2);
}
-class fib_task
+long parallel_fib( long n, long cutof)
{
-private:
- long cutof_;
-
-public:
- fib_task( long cutof)
- : cutof_( cutof)
- {}
-
- long execute( long n)
+ if ( n < cutof) return serial_fib( n);
+ else
{
- if ( n < cutof_) return serial_fib( n);
- else
- {
- BOOST_ASSERT( boost::this_task::runs_in_pool() );
- tsk::handle< long > h1(
- tsk::async(
- boost::this_task::get_pool< pool_type >(),
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 1) ) ) ;
- tsk::handle< long > h2(
- tsk::async(
- boost::this_task::get_pool< pool_type >(),
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 2) ) );
- return h1.get() + h2.get();
- }
+ BOOST_ASSERT( boost::this_task::runs_in_pool() );
+ tsk::handle< long > h1(
+ tsk::async(
+ tsk::as_sub_task(),
+ tsk::make_task(
+ parallel_fib,
+ n - 1,
+ cutof) ) ) ;
+ tsk::handle< long > h2(
+ tsk::async(
+ tsk::as_sub_task(),
+ tsk::make_task(
+ parallel_fib,
+ n - 2,
+ cutof) ) );
+ return h1.get() + h2.get();
}
-};
-
-long parallel_fib( long n)
-{
- fib_task a( 5);
- return a.execute( n);
}
int main( int argc, char *argv[])
@@ -79,13 +62,14 @@
pt::ptime start( pt::microsec_clock::universal_time() );
- for ( int i = 0; i < 15; ++i)
+ for ( int i = 0; i < 10; ++i)
results.push_back(
tsk::async(
pool,
tsk::make_task(
& parallel_fib,
- i) ) );
+ i,
+ 5) ) );
tsk::waitfor_all( results.begin(), results.end() );