Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53533 - in sandbox/task/libs/task/doc: . html html/boost_task html/images html/images/accumulators html/images/callouts
From: oliver.kowalke_at_[hidden]
Date: 2009-06-01 08:13:07


Author: olli
Date: 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
New Revision: 53533
URL: http://svn.boost.org/trac/boost/changeset/53533

Log:
* documentation

Added:
   sandbox/task/libs/task/doc/boost.png (contents, props changed)
   sandbox/task/libs/task/doc/boost_task.xml (contents, props changed)
   sandbox/task/libs/task/doc/fork_join.qbk (contents, props changed)
   sandbox/task/libs/task/doc/html/
   sandbox/task/libs/task/doc/html/boost_task/
   sandbox/task/libs/task/doc/html/boost_task/appendices.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/as_sub_task.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/async_completion_token.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/async_executor.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/callable.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/description.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/handle.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/meta_functions.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/motivation.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/new_thread.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/own_thread.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/pool.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/reference.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/task.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boost_task/utilities.html (contents, props changed)
   sandbox/task/libs/task/doc/html/boostbook.css (contents, props changed)
   sandbox/task/libs/task/doc/html/docutils.css (contents, props changed)
   sandbox/task/libs/task/doc/html/images/
   sandbox/task/libs/task/doc/html/images/accumulators/
   sandbox/task/libs/task/doc/html/images/accumulators/doxygen.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_0.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_1.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_10.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_100.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_11.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_12.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_13.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_14.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_15.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_16.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_17.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_18.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_19.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_2.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_20.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_21.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_22.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_23.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_24.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_25.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_26.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_27.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_28.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_29.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_3.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_30.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_31.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_32.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_33.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_34.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_35.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_36.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_37.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_38.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_39.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_4.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_40.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_41.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_42.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_43.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_44.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_45.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_46.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_47.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_48.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_49.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_5.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_50.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_51.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_52.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_53.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_54.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_55.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_56.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_57.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_58.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_59.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_6.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_60.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_61.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_62.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_63.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_64.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_65.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_66.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_67.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_68.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_69.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_7.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_70.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_71.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_72.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_73.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_74.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_75.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_76.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_77.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_78.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_79.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_8.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_80.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_81.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_82.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_83.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_84.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_85.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_86.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_87.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_88.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_89.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_9.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_90.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_91.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_92.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_93.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_94.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_95.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_96.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_97.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_98.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/accumulators/form_99.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/alert.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/blank.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/
   sandbox/task/libs/task/doc/html/images/callouts/1.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/10.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/11.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/12.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/13.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/14.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/15.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/2.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/3.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/4.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/5.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/6.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/7.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/8.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/callouts/9.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/caution.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/draft.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/home.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/important.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/next.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/next_disabled.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/note.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/prev.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/prev_disabled.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/smiley.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/tip.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/toc-blank.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/toc-minus.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/toc-plus.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/up.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/up_disabled.png (contents, props changed)
   sandbox/task/libs/task/doc/html/images/warning.png (contents, props changed)
   sandbox/task/libs/task/doc/html/index.html (contents, props changed)
   sandbox/task/libs/task/doc/html/minimal.css (contents, props changed)
   sandbox/task/libs/task/doc/html/reference.css (contents, props changed)
Removed:
   sandbox/task/libs/task/doc/description.qbk
   sandbox/task/libs/task/doc/forkjoin.qbk
Text files modified:
   sandbox/task/libs/task/doc/Jamfile.v2 | 4 +-
   sandbox/task/libs/task/doc/appendices.qbk | 4 +-
   sandbox/task/libs/task/doc/as_sub_task.qbk | 2
   sandbox/task/libs/task/doc/boost_task.qbk | 44 ++++++++++++++++++++++---------------
   sandbox/task/libs/task/doc/channel.qbk | 9 ++++---
   sandbox/task/libs/task/doc/default_pool.qbk | 5 ++-
   sandbox/task/libs/task/doc/handle.qbk | 8 +++++-
   sandbox/task/libs/task/doc/introduction.qbk | 39 +++++++++++++++++---------------
   sandbox/task/libs/task/doc/meta_functions.qbk | 3 +
   sandbox/task/libs/task/doc/new_thread.qbk | 31 ++++++++++++++-----------
   sandbox/task/libs/task/doc/overview.qbk | 26 +++++++++++----------
   sandbox/task/libs/task/doc/own_thread.qbk | 2
   sandbox/task/libs/task/doc/pool.qbk | 10 +++++---
   sandbox/task/libs/task/doc/processor_binding.qbk | 2
   sandbox/task/libs/task/doc/ref_async.qbk | 2
   sandbox/task/libs/task/doc/ref_task.qbk | 2
   sandbox/task/libs/task/doc/scheduler.qbk | 22 ++++++-----------
   sandbox/task/libs/task/doc/shutdown.qbk | 10 ++++----
   sandbox/task/libs/task/doc/static_pool.qbk | 17 +++++++------
   sandbox/task/libs/task/doc/task.qbk | 34 +++++++++++++++-------------
   sandbox/task/libs/task/doc/todo.qbk | 36 ++++++++++++++++++-----------
   sandbox/task/libs/task/doc/utilities.qbk | 10 ++++----
   sandbox/task/libs/task/doc/work_stealing.qbk | 47 ++++++++++++++++++++-------------------
   23 files changed, 200 insertions(+), 169 deletions(-)

Modified: sandbox/task/libs/task/doc/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/doc/Jamfile.v2 (original)
+++ sandbox/task/libs/task/doc/Jamfile.v2 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -8,5 +8,5 @@
 
 using quickbook ;
 
-xml threadpool : threadpool.qbk ;
-boostbook standalone : threadpool ;
+xml task : boost_task.qbk ;
+boostbook standalone : task ;

Modified: sandbox/task/libs/task/doc/appendices.qbk
==============================================================================
--- sandbox/task/libs/task/doc/appendices.qbk (original)
+++ sandbox/task/libs/task/doc/appendices.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -8,9 +8,9 @@
 
 [section Appendices]
 
-[include rationale.qbk]
-[include acknowledgements.qbk]
+[/ [include rationale.qbk] ]
 [include todo.qbk]
+[include acknowledgements.qbk]
 
 
 [endsect]

Modified: sandbox/task/libs/task/doc/as_sub_task.qbk
==============================================================================
--- sandbox/task/libs/task/doc/as_sub_task.qbk (original)
+++ sandbox/task/libs/task/doc/as_sub_task.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -6,7 +6,7 @@
 ]
 
 
-[section:as_sub_task __as_sub_task__]
+[section:as_sub_task Execute as sub-task]
 
 __as_sub_task__ is a convenient way to execute a __sub_task__. If the parent task is executed inside a __thread_pool__ the __sub_task__ is put into the local-queue of the
 __worker_thread__ in the other case the __sub_task__ will be executed in a new thread.

Added: sandbox/task/libs/task/doc/boost.png
==============================================================================
Binary file. No diff available.

Modified: sandbox/task/libs/task/doc/boost_task.qbk
==============================================================================
--- sandbox/task/libs/task/doc/boost_task.qbk (original)
+++ sandbox/task/libs/task/doc/boost_task.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -24,16 +24,13 @@
 [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_act[link_text] [link boost_task.async_completion_token [link_text]]]
-[template link_ae[link_text] [link boost_task.async_executor [link_text]]]
-[template link_coop_task[link_text] [link boost_task.task.cooperative [link_text]]]
-[template link_channel[link_text] [link boost_task.async_executor.pool.channel [link_text]]]
-[template link_forkjoin[link_text] [link boost_task.async_executor.pool.forkjoin [link_text]]]
-[template link_handle[link_text] [link boost_task.async_completion_token.handle [link_text]]]
-[template link_own_thread[link_text] [link boost_task.async_executor.own_thread [link_text]]]
-[template link_pool[link_text] [link boost_task.async_executor.pool [link_text]]]
+[template link_channel[link_text] [link boost_task.pool.channel [link_text]]]
+[template link_forkjoin[link_text] [link boost_task.pool.forkjoin [link_text]]]
+[template link_handle[link_text] [link boost_task.handle [link_text]]]
+[template link_own_thread[link_text] [link boost_task.own_thread [link_text]]]
+[template link_pool[link_text] [link boost_task.pool [link_text]]]
 [template link_task[link_text] [link boost_task.task [link_text]]]
-[template link_work_stealing[link_text] [link boost_task.async_executor.pool.work_stealing [link_text]]]
+[template link_work_stealing[link_text] [link boost_task.pool.work_stealing [link_text]]]
 
 [def __thread__ `boost::thread`]
 [def __thread_id__ `boost::thread::id`]
@@ -79,6 +76,7 @@
 
 [def __fn_active__ `active()`]
 [def __fn_closed__ `close()`]
+[def __fn_clear__ `clear()`]
 [def __fn_empty__ `empty()`]
 [def __fn_get__ `get()`]
 [def __fn_get_id__ `get_id()`]
@@ -87,26 +85,28 @@
 [def __fn_has_exception__ `has_exception()`]
 [def __fn_idle__ `idle()`]
 [def __fn_interrupt__ `interrupt()`]
+[def __fn_interrupt_and_wait__ `interrupt_and_wait()`]
 [def __fn_interrupt_and_wait_for__ `interrupt_and_wait_for()`]
 [def __fn_interrupt_and_wait_until__ `interrupt_and_wait_until()`]
 [def __fn_interruption_requested__ `interruption_requested()`]
 [def __fn_is_ready__ `is_ready()`]
 [def __fn_operator__ `operator()()`]
 [def __fn_pending__ `pending()()`]
-[def __fn_size__ size()`]
-[def __fn_shutdown__ shutdown()`]
-[def __fn_shutdown_now__ shutdown_now()`]
+[def __fn_size__ `size()`]
+[def __fn_shutdown__ `shutdown()`]
+[def __fn_shutdown_now__ `shutdown_now()`]
 [def __fn_wait__ `wait()`]
 [def __fn_wait_for__ `wait_for()`]
 [def __fn_wait_until__ `wait_until()`]
 
-[def __act__ `asynchronous-completion-token`]
-[def __ae__ `asynchronous-executor`]
-[def __aes__ `asynchronous-executors`]
+[def __act__ ['asynchronous-completion-token]]
+[def __ae__ ['asynchronous-executor]]
+[def __aes__ ['asynchronous-executors]]
 [def __blocked__ ['blocked]]
 [def __callable__ ['callable]]
-[def __coop_task__ `cooperative task`]
-[def __duration__ `Duration`]
+[def __channel__ ['channel]]
+[def __coop_task__ ['cooperative task]]
+[def __duration__ ['Duration]]
 [def __fork_join__ ['fork/join]]
 [def __interruption_point__ ['interruption-point]]
 [def __interruption_points__ ['interruption-points]]
@@ -124,6 +124,14 @@
 
 
 [include overview.qbk]
-[include description.qbk]
+[include introduction.qbk]
+[include task.qbk]
+[include handle.qbk]
+[include own_thread.qbk]
+[include new_thread.qbk]
+[include pool.qbk]
+[include as_sub_task.qbk]
+[include utilities.qbk]
+[include meta_functions.qbk]
 [include reference.qbk]
 [include appendices.qbk]

Added: sandbox/task/libs/task/doc/boost_task.xml
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/boost_task.xml 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,4225 @@
+<?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_task" name="Boost.Task" dirname="boost_task" last-revision="$Date: 2009/06/01 12:11:53 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+ <libraryinfo>
+ <authorgroup>
+ <author>
+ <firstname>Oliver</firstname> <surname>Kowalke</surname>
+ </author>
+ </authorgroup>
+ <copyright>
+ <year>2009</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 asynchronous execution of tasks
+ </librarypurpose>
+ <librarycategory name="category:text"></librarycategory>
+ </libraryinfo>
+ <title>Boost.Task</title>
+ <section id="boost_task.overview">
+ <title><link linkend="boost_task.overview"> Overview</link></title>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> provides an framework for parallel
+ execution of tasks (a task is a small unit of code that can be executed independently).
+ </para>
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code>, <emphasis>callable</emphasis> representing
+ a fine-grained work-item:
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">get_id</phrase><phrase role="special">()</phrase></code>
+ returning an identifier
+ </listitem>
+ <listitem>
+ <code><phrase role="keyword">operator</phrase><phrase role="special">()()</phrase></code>
+ to execute the fine-grained work-item
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">get_future</phrase><phrase role="special">()</phrase></code>
+ providing an <emphasis>asynchronous-completion-token</emphasis> in order
+ to pass the result (values, exceptions) back to initiator
+ </listitem>
+ </itemizedlist>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">handle</phrase></code>, <emphasis>asynchronous-completion-token</emphasis>
+ of the asynchronously executed task:
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">get_id</phrase><phrase role="special">()</phrase></code>
+ for identifying associated task
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">interrupt</phrase><phrase role="special">()</phrase></code>,
+ interrupt_and_wait() allow to cancel an cooperative task
+ </listitem>
+ <listitem>
+ interface of <emphasis>asynchronous-completion-token</emphasis>:
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">get</phrase><phrase role="special">()</phrase></code>
+ retrieve value or exception of task execution
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">is_ready</phrase><phrase role="special">()</phrase></code>
+ test if task was executed
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">wait</phrase><phrase role="special">()</phrase></code>,
+ <code><phrase role="identifier">wait_for</phrase><phrase role="special">()</phrase></code>
+ and <code><phrase role="identifier">wait_until</phrase><phrase role="special">()</phrase></code>
+ block until task is executed and the result is set
+ </listitem>
+ </itemizedlist>
+ </listitem>
+ </itemizedlist>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">async</phrase><phrase role="special">()</phrase></code>,
+ executes a task on behalf of <emphasis>asynchronous-executors</emphasis>
+ </listitem>
+ <listitem>
+ <emphasis>asynchronous-executor</emphasis> models:
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">own_thread</phrase></code>: executes task in current
+ thread.
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">new_thread</phrase></code>: executes task in a newly
+ created thread (thread will be destroyed after)
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">default_pool</phrase></code>: task gets executed by
+ a <emphasis>worker-thread</emphasis> of the default <emphasis>thread-pool</emphasis>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">as_sub_task</phrase></code>: executes task in newly
+ created thread or in a pool of <emphasis>worker-threads</emphasis> depending
+ on whether current task is already executed in a pool
+ </listitem>
+ <listitem>
+ custom pool: task gets executed by a <emphasis>worker-thread</emphasis>
+ of a custom <emphasis>thread-pool</emphasis>
+ </listitem>
+ </itemizedlist>
+ </listitem>
+ </itemizedlist>
+ <para>
+ References
+ </para>
+ <itemizedlist>
+ <listitem>
+ N2185: Proposed Text for Parallel Task Execution <ulink url="
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2185.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2185.html>
+ written by Peter Dimov.
+ </listitem>
+ <listitem>
+ N2276: Thread Pools and Futures <ulink url="
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2276.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2276.html>
+ written by Anthony Williams.
+ </listitem>
+ <listitem>
+ N2802: A plea to reconsider detach-on-destruction for thread objects <ulink
+ url="
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2802.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2802.html>
+ written by Hans-J. Boehm.
+ </listitem>
+ <listitem>
+ <ulink url="
http://herbsutter.wordpress.com">'Sutter’s Mill'</ulink> by
+ Herb Sutter
+ </listitem>
+ <listitem>
+ mailing list of C++ standard committee's Library Working Group
+ </listitem>
+ </itemizedlist>
+ <note>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> uses <ulink url="http://www.justsoftwaresolutions.co.uk/threading/updated-implementation-of-c++-futures-3.html"><emphasis
+ role="bold">Boost.Future</emphasis></ulink> from Anthony Williams (will be
+ integrated in some of the next releases of <ulink url="http://www.boost.org/libs/thread"><emphasis
+ role="bold">Boost.Thread</emphasis></ulink>).
+ </para>
+ </note>
+ <para>
+ In order to use the classes and functions described here, you can either include
+ the specific headers specified by the descriptions of each class or function,
+ or include the master library header:
+ </para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+</programlisting>
+ <para>
+ which includes all the other headers in turn.
+ </para>
+ <anchor id="boost_task.overview.tested_platforms"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.overview.tested_platforms">Tested Platforms</link>
+ </bridgehead>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> has been tested on the following
+ platforms and compilers:
+ </para>
+ <itemizedlist>
+ <listitem>
+ Debian GNU/Linux 2.6.29.2 (x86_64), GCC 4.3.3
+ </listitem>
+ <listitem>
+ Ubuntu GNU/Linux 2.6.28.11 (x86), GCC 4.3.3
+ </listitem>
+ <listitem>
+ FreeBSD 7.2 (x86), GCC 4.2.1
+ </listitem>
+ <listitem>
+ OpenSolaris 0811 (x86_64), SunCC 5.10
+ </listitem>
+ <listitem>
+ Windows XP Professional (x86), MSVC 9.0
+ </listitem>
+ </itemizedlist>
+ <anchor id="boost_task.overview.how_to_build"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.overview.how_to_build">How to build</link>
+ </bridgehead>
+ <itemizedlist>
+ <listitem>
+ download the sources form <ulink url="http://www.boostpro.com/vault/index.php">boost-vault</ulink>
+ (section <emphasis>Concurrent Programing</emphasis>) or <ulink url="https://svn.boost.org/svn/boost/sandbox/task/">boost-sandbox</ulink>
+ </listitem>
+ <listitem>
+ extract the archive into the boost-source directory
+ </listitem>
+ <listitem>
+ change directory to &lt;boost-source&gt;/libs/task/build
+ </listitem>
+ <listitem>
+ call <code><phrase role="identifier">bjam</phrase> <phrase role="identifier">toolset</phrase><phrase
+ role="special">=&lt;</phrase><phrase role="identifier">compiler</phrase><phrase
+ role="special">-</phrase><phrase role="identifier">name</phrase><phrase role="special">&gt;</phrase></code>
+ </listitem>
+ </itemizedlist>
+ </section>
+ <section id="boost_task.motivation">
+ <title><link linkend="boost_task.motivation"> Motivation</link></title>
+ <para>
+ To speed-up computer-bound work and/or increase the computation-throughput
+ is a common motivation for parallelizing a program. Especially for interactive
+ applications that have to process user input while performing some background
+ tasks responsivness iss very important. Parallelizing a program requires partitioning
+ the program into smaller chunks that can run in parallel. The code can scale
+ as the hardware gets better without changing the code.
+ </para>
+ <para>
+ The evolution from one-core to many-core architectures and the usage of threads
+ (of course processes fit too) support this paradigm.
+ </para>
+ <note>
+ <para>
+ <quote>You can have multithreading on a single core machine, but you can
+ only have parallelism on a multi core machine ... .</quote> -- Daniel Moth
+ <footnote>
+ <para>
+ more to read at Daniel's <ulink url="http://www.danielmoth.com/Blog/2008/11/threadingconcurrency-vs-parallelism.html">blog</ulink>
+ </para>
+ </footnote>
+ </para>
+ </note>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> provides a framework to utilize
+ the available hardware and provide a way for efficient asynchronous processing
+ of time consuming operations. The framework provides some <emphasis>asynchronous-executors</emphasis>,
+ like <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase></code>,
+ in order to execute the task asynchronously in another execution context (<emphasis
+ role="bold">Boost.Task</emphasis> uses preemptible threads for this purpose).
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">print</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase> <phrase role="identifier">printf</phrase><phrase role="special">(</phrase><phrase role="string">&quot;%s\n&quot;</phrase><phrase role="special">,</phrase> <phrase role="identifier">msg</phrase><phrase role="special">.</phrase><phrase role="identifier">c_str</phrase><phrase role="special">()</phrase> <phrase role="special">);</phrase> <phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase> <phrase role="comment">// dispatchs task
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// task, to be executed asynchronously
+</phrase> <phrase role="identifier">print</phrase><phrase role="special">,</phrase>
+ <phrase role="string">&quot;Hello World!&quot;</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <para>
+ In order to manage the task <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">async</phrase><phrase role="special">()</phrase></code> returns
+ a handle <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase></code>
+ (associated with the submitted task). It functions as a <emphasis>asynchronous-completion-token</emphasis>
+ - that means it transfers the result of the execution back to the caller thread.
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">echo</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">msg</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase> <phrase role="comment">// get handle associated with the task
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// task, to be executed asynchronously
+</phrase> <phrase role="identifier">echo</phrase><phrase role="special">,</phrase>
+ <phrase role="string">&quot;Hello World!&quot;</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// wait until task is finished and return the result
+</phrase><phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <para>
+ The task can also be interrupted via <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">handle</phrase></code> if it is a so-called <link linkend="boost_task.task"><emphasis>cooperative
+ task</emphasis></link>.
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">long_running</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">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">rel_time</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase> <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> <phrase role="identifier">rel_time</phrase><phrase role="special">);</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase> <phrase role="comment">// get handle associated with the task
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// long runing task, to be executed asynchronously
+</phrase> <phrase role="identifier">long_running</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">millisec</phrase><phrase role="special">(</phrase> <phrase role="number">500</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">interrupt</phrase><phrase role="special">();</phrase> <phrase role="comment">// interrupt execution of task
+</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// wait until task is finished, will throw an exeception
+</phrase><phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <para>
+ Beside <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase></code>
+ (which creates a new task for each submitted task) <emphasis role="bold">Boost.Task</emphasis>
+ provides <link linkend="boost_task.pool"><emphasis>thread-pools</emphasis></link>
+ to prevent the overhead of thread creation and destruction for each task.
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">default_pool</phrase></code>
+ submitts the tasks to the default <emphasis>thread-pool</emphasis> which contains
+ a fixed number of pre-spawned <emphasis>worker-threads</emphasis> (custom
+ <emphasis>thread-pools</emphasis> are supported too).
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">serial_fib</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="number">2</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">serial_fib</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="identifier">serial_fib</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="keyword">long</phrase> <phrase role="identifier">parallel_fib</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">,</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">cutof</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">serial_fib</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="comment">// fork a sub-task calculating fibonacci(n-1)
+</phrase> <phrase role="identifier">h1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</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_pool</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">parallel_fib</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="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="comment">// fork a sub-task calculating fibonacci(n-2)
+</phrase> <phrase role="identifier">h2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</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_pool</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">parallel_fib</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="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="comment">// join the results of both sub-tasks
+</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">h1</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">h2</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">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase> <phrase role="comment">// handle for fibonacci calculation
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">default_pool</phrase><phrase role="special">(),</phrase> <phrase role="comment">// access the default thread-pool
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// calculate fibonacci number 10
+</phrase> <phrase role="identifier">parallel_fib</phrase><phrase role="special">,</phrase> <phrase role="comment">// for numbers &lt; 5 do inline recursive calculation
+</phrase> <phrase role="number">10</phrase><phrase role="special">,</phrase>
+ <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <para>
+ With function <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">runs_in_pool</phrase><phrase role="special">()</phrase></code>
+ a task can detect if it is executed inside a <emphasis>thread-pool</emphasis>.
+ <emphasis>sub-tasks</emphasis> arecreated by <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">as_sub_task</phrase></code>. Where the <emphasis>sub-task</emphasis>
+ is executed by a new thread if the parent task is not executed inside a <emphasis>thread-pool</emphasis>.
+ In the other case the <emphasis>sub-task</emphasis> is put into the local
+ <emphasis>worker-queue</emphasis> which enables <link linkend="boost_task.pool.work_stealing"><emphasis>work-stealing</emphasis></link>
+ and <link linkend="boost_task.pool.forkjoin">inline execution</link> of tasks.
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">as_sub_task</phrase><phrase role="special">(),</phrase> <phrase role="comment">// sub-task executed in a new thread or inside
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// the thread-pool depending upon the parent
+</phrase> <phrase role="identifier">parallel_fib</phrase><phrase role="special">,</phrase> <phrase role="comment">// task is executed inside a thread-pool or not
+</phrase> <phrase role="number">10</phrase><phrase role="special">,</phrase>
+ <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.task">
+ <title><link linkend="boost_task.task"> Task</link></title>
+ <para>
+ A task is a chunk of code that can be executed independently.
+ </para>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ represents a <emphasis>callable</emphasis> (provides <code><phrase role="keyword">operator</phrase><phrase
+ role="special">()()</phrase></code>) object containing the unit of code to
+ be execute by a <emphasis>asynchronous-executor</emphasis>. Function <code><phrase
+ role="identifier">get_future</phrase><phrase role="special">()</phrase></code>
+ returns a <emphasis>asynchronous-completion-token</emphasis> allowing to wait
+ for the completion of the computation of the task, for getting the result of
+ a computation or for transfering exceptions. Each <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> has a unique identifier.
+ </para>
+ <anchor id="boost_task.task.creation"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.task.creation">Creation</link>
+ </bridgehead>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase
+ role="special">()</phrase></code> can be used to create <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> by passing free-functions or member-functions
+ of objects and its arguments: <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">make_task</phrase><phrase role="special">()</phrase></code>
+ accepts up to ten arguments per default (can be overriden by defining BOOST_TASK_MAKE_TASK_MAX_ARITY
+ with the new value).
+ </para>
+ <itemizedlist>
+ <listitem>
+ create task from free-function with arguments:
+ </listitem>
+ </itemizedlist>
+ <para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">parallel_fib</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ <itemizedlist>
+ <listitem>
+ create task from member-function with arguments:
+ </listitem>
+ </itemizedlist>
+ <para>
+
+<programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">X</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="identifier">X</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
+<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="special">&amp;</phrase> <phrase role="identifier">X</phrase><phrase role="special">::</phrase><phrase role="identifier">f</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">x</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ <para>
+ It is possible to create <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> from a <emphasis>callable</emphasis>
+ too:
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">struct</phrase> <phrase role="identifier">Y</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()();</phrase>
+<phrase role="special">};</phrase>
+
+<phrase role="identifier">Y</phrase> <phrase role="identifier">y</phrase><phrase role="special">;</phrase>
+<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">(</phrase> <phrase role="identifier">y</phrase><phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ <anchor id="boost_task.task.cooperative_task_and_interruption"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.task.cooperative_task_and_interruption">Cooperative
+ task and interruption</link>
+ </bridgehead>
+ <para>
+ Sometimes it is desired to stop a running task if it is no longer needed. In
+ this case the thread is not killed - it stops only at well-defined points (<emphasis>interruption-points</emphasis>)
+ its execution. In the context of task-interruption a task is known as cooperative
+ if it checks for an interruption request between two <emphasis>interruption-points</emphasis>
+ via <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">this_thread</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">interruption_requested</phrase><phrase role="special">()</phrase></code>
+ <footnote>
+ <para>
+ see <ulink url="http://www.ddj.com/architect/207100682">'Interrupt Politely'</ulink>,
+ Herb Sutter
+ </para>
+ </footnote>
+ .
+ </para>
+ <para>
+ <emphasis>interruption-points</emphasis> are:
+ </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>
+ <para>
+ A <emphasis>interruption-point</emphasis> throws <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task_interrupted</phrase></code> if an interruption was requested.
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">cooperative</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <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> <phrase role="comment">// interruption point
+</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_thread</phrase><phrase role="special">::</phrase><phrase role="identifier">interruption_requested</phrase><phrase role="special">()</phrase> <phrase role="special">)</phrase> <phrase role="comment">// check if interruption was requested
+</phrase> <phrase role="keyword">return</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+
+ <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> <phrase role="comment">// interruption point
+</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase> <phrase role="comment">// get handle associated with the task
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// task, to be executed asynchronously
+</phrase> <phrase role="identifier">cooperative</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// throws boost::task::task_interrupted
+</phrase><phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <anchor id="boost_task.task.exceptions"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.task.exceptions">Exceptions</link>
+ </bridgehead>
+ <para>
+ Exceptions thrown by <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> are transported by the <emphasis>asynchronous-completion-token</emphasis>.
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">throwing</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="special">...</phrase>
+ <phrase role="keyword">throw</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">domain_error</phrase><phrase role="special">(</phrase><phrase role="string">&quot;domain error&quot;</phrase><phrase role="special">);</phrase>
+ <phrase role="special">...</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase> <phrase role="comment">// get handle associated with the task
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// task, to be executed asynchronously
+</phrase> <phrase role="identifier">throwing</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">wait</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// throws std::domain_error
+</phrase><phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <para>
+ Exceptions rethrown by type are:
+ </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">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">exception</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">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task_interrupted</phrase></code>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">broken_task</phrase></code>
+ </listitem>
+ </itemizedlist>
+ <anchor id="boost_task.task.parent_task"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.task.parent_task">Parent task</link>
+ </bridgehead>
+ <para>
+ Top-level tasks have no parent. A parent task can create child tasks when it
+ creates another task by using <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">as_sub_task</phrase></code> as <emphasis>asynchronous-executor</emphasis>.
+ These children are implicitly treated as <emphasis>sub-tasks</emphasis> of
+ the larger task. It is assumed that that <emphasis>sub-tasks</emphasis> can
+ be executed in any order because only overall operation speed matters (enabling
+ strategies for fast execution of unordered <emphasis>work-items</emphasis>
+ as <link linkend="boost_task.pool.work_stealing"><emphasis>work-stealing</emphasis></link>).
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">serial_fib</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="number">2</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">serial_fib</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="identifier">serial_fib</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="keyword">long</phrase> <phrase role="identifier">parallel_fib</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">,</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">cutof</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">serial_fib</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="comment">// submit a sub-task to pool calculating fibonacci(n-1)
+</phrase> <phrase role="identifier">h1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">as_sub_task</phrase><phrase role="special">(),</phrase> <phrase role="comment">// execute a sub-task
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">parallel_fib</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="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="comment">// submit a sub-task to pool calculating fibonacci(n-2)
+</phrase> <phrase role="identifier">h2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">as_sub_task</phrase><phrase role="special">(),</phrase> <phrase role="comment">// execute a sub-task
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">parallel_fib</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="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="comment">// calculate fibonacci(n) from the results of both sub-tasks
+</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">h1</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">h2</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">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase> <phrase role="comment">// handle for fibonacci calculation
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">default_pool</phrase><phrase role="special">(),</phrase> <phrase role="comment">// access the default thread-pool
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// calculate fibonacci number 10
+</phrase> <phrase role="identifier">parallel_fib</phrase><phrase role="special">,</phrase> <phrase role="comment">// for numbers &lt; 5 do inline recursive calculation
+</phrase> <phrase role="number">10</phrase><phrase role="special">,</phrase>
+ <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.handle">
+ <title><link linkend="boost_task.handle"> Handle</link></title>
+ <para>
+ The <emphasis>asynchronous-completion-token</emphasis> dispatches tasks in
+ response to the completion of asynchronous operations. <emphasis>asynchronous-completion-token</emphasis>
+ uniquely identifies the task and state necessary to process the result of the
+ operation
+ <footnote>
+ <para>
+ see <ulink url="http://www.cs.wustl.edu/~schmidt/PDF/ACT.pdf">'Asynchronous
+ Completion Token'</ulink>, Douglas Schmidt
+ </para>
+ </footnote>
+ .
+ </para>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase></code>
+ represents an <emphasis>asynchronous-completion-token</emphasis>. It will be
+ returned by <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase
+ role="special">()</phrase></code> and is associated with the submitted <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase></code>.
+ </para>
+ <anchor id="boost_task.handle.asynchronous_completion_token_interface"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.handle.asynchronous_completion_token_interface">Asynchronous
+ completion token interface</link>
+ </bridgehead>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase></code>
+ implements an interface in order to check the state of computation and result
+ transfer
+ </para>
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">get_id</phrase><phrase role="special">()</phrase></code>:
+ return id of the associated task-id
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">is_ready</phrase><phrase role="special">()</phrase></code>:
+ test if result is set
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">has_value</phrase><phrase role="special">()</phrase></code>:
+ test if value-result is set
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">has_exception</phrase><phrase role="special">()</phrase></code>:
+ test if exception-result is set
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">get</phrase><phrase role="special">()</phrase></code>:
+ return value-result
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">wait</phrase><phrase role="special">()</phrase></code>:
+ wait until result is set
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">wait_for</phrase><phrase role="special">()</phrase></code>:
+ wait until result is set or time-duration has elapsed
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">wait_until</phrase><phrase role="special">()</phrase></code>:
+ wait until result ist set or time-point has elapsed
+ </listitem>
+ </itemizedlist>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">fibonacci</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <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> <phrase role="comment">// interruption point
+</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_thread</phrase><phrase role="special">::</phrase><phrase role="identifier">interruption_requested</phrase><phrase role="special">()</phrase> <phrase role="special">)</phrase> <phrase role="comment">// check if interruption was requested
+</phrase> <phrase role="keyword">return</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+
+ <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> <phrase role="comment">// interruption point
+</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">fibonacci</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;id == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get_id</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;is ready == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">is_ready</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">wait</phrase><phrase role="special">();</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;has value == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">has_value</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;has exception == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">has_exception</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(10) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <anchor id="boost_task.handle.task_interruption"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.handle.task_interruption">Task interruption</link>
+ </bridgehead>
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">interrupt</phrase><phrase role="special">()</phrase></code>:
+ interrupt <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> and return immediately
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">()</phrase></code>:
+ interrupt and wait until <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ was removed from <emphasis>worker-thread</emphasis>
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">interrupt_and_wait_for</phrase><phrase role="special">()</phrase></code>:
+ interrupt and wait until <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ was removed from <emphasis>worker-thread</emphasis> or time duration has
+ elapsed
+ </listitem>
+ <listitem>
+ <code><phrase role="identifier">interrupt_and_wait_until</phrase><phrase
+ role="special">()</phrase></code>: interrupt and wait until <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> was removed from <emphasis>worker-thread</emphasis>
+ or time point has elapsed
+ </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_requested</phrase><phrase role="special">()</phrase></code>:
+ return bool if interruption was requested
+ </listitem>
+ </itemizedlist>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">cooperative</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <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> <phrase role="comment">// interruption point
+</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_thread</phrase><phrase role="special">::</phrase><phrase role="identifier">interruption_requested</phrase><phrase role="special">()</phrase> <phrase role="special">)</phrase> <phrase role="comment">// check if interruption was requested
+</phrase> <phrase role="keyword">return</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+
+ <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> <phrase role="comment">// interruption point
+</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase> <phrase role="comment">// get handle associated with the task
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// task, to be executed asynchronously
+</phrase> <phrase role="identifier">cooperative</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">h</phrase><phrase role="special">.</phrase><phrase role="identifier">interrupt_and_wait</phrase><phrase role="special">();</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;id == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get_id</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;is ready == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">is_ready</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;has value == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">has_value</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;has exception == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">has_exception</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// throws boost::task::task_interrupted
+</phrase><phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.own_thread">
+ <title><link linkend="boost_task.own_thread"> Execute in own thread</link></title>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">own_thread</phrase></code>
+ executes the task in the current thread (synchronous execution - concerns of
+ <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2802.html">N2802</ulink>
+ do not aply).
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">fibonacci</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</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">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">own_thread</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">fibonacci</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(10) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.new_thread">
+ <title><link linkend="boost_task.new_thread"> Execute in new thread</link></title>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase></code>
+ creates a new <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread</phrase></code> and executes the task in this thread
+ (asynchronous). The created thread gets joined by handle (so <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2802.html">N2802</ulink>
+ should be addressed).
+ </para>
+ <caution>
+ <para>
+ Always store the returned <emphasis>asynchronous-completion-token</emphasis>
+ in a variable because <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">handle</phrase></code>
+ joins the thread in its destructor (if the last reference gets out of scope).
+ </para>
+ </caution>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">fibonacci</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</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">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">fibonacci</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(10) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <para>
+ In the example below both <code><phrase role="identifier">a_function</phrase><phrase
+ role="special">()</phrase></code> and <code><phrase role="identifier">another_function</phrase><phrase
+ role="special">()</phrase></code> are executed synchron (see <link linkend="boost_task.own_thread"><code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">own_thread</phrase></code></link>
+ for synchronous execution)!
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">a_function</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">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">another_function</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.pool">
+ <title><link linkend="boost_task.pool"> Thread-pool</link></title>
+ <para>
+ Instead of creating a new thread and quickly throwing it away after the task
+ is done, the overhead related to thread creation and destruction can be avoided
+ by running the <emphasis>work-items</emphasis> on a <emphasis>thread-pool</emphasis>
+ (reusing an existing <emphasis>worker-thread</emphasis> instead).
+ </para>
+ <para>
+ A <emphasis>thread-pool</emphasis> maintains a queue (or queues) of <emphasis>work-items</emphasis>
+ to be done, and a pool of <emphasis>worker-threads</emphasis> which execute
+ <emphasis>work-items</emphasis> from the queue(s).
+ </para>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> provides <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">async</phrase><phrase role="special">()</phrase></code> with
+ support of executing an <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> in <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">default_pool</phrase></code> (using <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">default_pool</phrase><phrase role="special">()</phrase></code>):
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">echo</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">msg</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">default_pool</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">echo</phrase><phrase role="special">,</phrase>
+ <phrase role="string">&quot;Hello World!&quot;</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <para>
+ and a custom <emphasis>thread-pool</emphasis> (passing pool instance as an
+ argument to <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase
+ role="special">()</phrase></code>):
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">echo</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">msg</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
+
+<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase>
+ <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</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">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">echo</phrase><phrase role="special">,</phrase>
+ <phrase role="string">&quot;Hello World!&quot;</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ .
+ </para>
+ <important>
+ <para>
+ Tasks should not be too small (performance overhead dominates) and avoid
+ blocking tasks
+ <footnote>
+ <para>
+ see <ulink url="http://www.ddj.com/go-parallel/article/showArticle.jhtml?articleID=216500409">'Use
+ Thread Pools Correctly'</ulink>, Herb Sutter
+ </para>
+ </footnote>
+ .
+ </para>
+ </important>
+ <section id="boost_task.pool.static_pool">
+ <title><link linkend="boost_task.pool.static_pool"> Static thread-pool</link></title>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> provides <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">static_pool</phrase></code>
+ - which contains an fixed set of pre-forked <emphasis>worker-threads</emphasis>
+ (the size of the pool doesn't change during its lifetime).
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">_static_pool</phrase><phrase role="special">&lt;</phrase> <phrase role="comment">// pool type
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase> <phrase role="comment">// queuing policy (unbounded_channel, bounded_channel)
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="comment">// scheduling policy (fifo, priority, smart)
+</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</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="comment">// pool with 6 pre-forked worker-threads
+</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="comment">// time to sleep if no work-item available
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</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> <phrase role="comment">// iterations over local-queues before sleep
+</phrase></programlisting>
+ </para>
+ <para>
+ The first argument of the constructor specifies how many <emphasis>worker-threads</emphasis>
+ the pool will contain. The second and third argument are used by the <link
+ linkend="boost_task.pool.work_stealing"><emphasis>work-stealing</emphasis></link>
+ algorithm.
+ </para>
+ <note>
+ <para>
+ If <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">bounded_channel</phrase></code> is used as queuing policy
+ the constructor has two additional arguments .
+ </para>
+ </note>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">static_pool</phrase></code> provides functionality to check
+ the status of the pool - <code><phrase role="identifier">close</phrase><phrase
+ role="special">()</phrase></code> returns true when the pool was shutdown
+ and <code><phrase role="identifier">active</phrase><phrase role="special">()</phrase></code>
+ as well as <code><phrase role="identifier">idle</phrase><phrase role="special">()</phrase></code>
+ returning how many <emphasis>worker-threads</emphasis> are active (executing
+ a task) or idle. The size of the pool can be accessed over <code><phrase
+ role="identifier">size</phrase><phrase role="special">()</phrase></code>.
+ </para>
+ <para>
+ For infomational pruposes <code><phrase role="identifier">empty</phrase><phrase
+ role="special">()</phrase></code> and <code><phrase role="identifier">pending</phrase><phrase
+ role="special">()()</phrase></code> can be used in order to know if the global
+ task-queue is empty or how many tasks are waiting for execution. With <code><phrase
+ role="identifier">clear</phrase><phrase role="special">()</phrase></code>
+ all tasks are removed from the global-queue.
+ </para>
+ <note>
+ <para>
+ <code><phrase role="identifier">pending</phrase><phrase role="special">()()</phrase></code>
+ does not count tasks in the local-queues of the <emphasis>worker-threads</emphasis>.
+ </para>
+ </note>
+ </section>
+ <section id="boost_task.pool.channel">
+ <title><link linkend="boost_task.pool.channel"> Channel</link></title>
+ <para>
+ The channel synchronizes the access between non-pool threads (application
+ threads) and <emphasis>worker-threads</emphasis> and implements a queuing
+ policy (limitation of queued tasks).
+ </para>
+ <anchor id="boost_task.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__bounded_channel__phrase___code_"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__bounded_channel__phrase___code_"><code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">bounded_channel</phrase></code></link>
+ </bridgehead>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">bounded_channel</phrase></code> contains a single lock
+ in order to synchronize access to the queue. The number of pending tasks
+ 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">task</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 task will be set to sleep (blocked). If it is equal to <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">low_watermark</phrase></code> everytime a sleeping producer
+ thread will be woken up and puts its task if one worker thread has taken
+ a task from the channel. <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">low_watermark</phrase></code>
+ sets the threshold when blocked threads get woken up. If it is less than
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">high_watermark</phrase></code> all sleeping producer threads
+ will be woken up if the amount of pending tasks reaches <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">low_watermark</phrase></code>.
+ </para>
+ <anchor id="boost_task.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__unbounded_channel__phrase___code_"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__unbounded_channel__phrase___code_"><code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">unbounded_channel</phrase></code></link>
+ </bridgehead>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">unbounded_channel</phrase></code> contains a single lock
+ in order to synchronize access to the queue. An unlimited number of tasks
+ can be queued into this channel. The insertion of an <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ will never block. If the channel becomes empty <emphasis>worker-threads</emphasis>
+ will be set to sleep until new tasks are enqueued.
+ </para>
+ </section>
+ <section id="boost_task.pool.scheduling">
+ <title><link linkend="boost_task.pool.scheduling"> Scheduling</link></title>
+ <para>
+ The scheduling policy determines how tasks are scheduled inside the <emphasis>channel</emphasis>.
+ </para>
+ <anchor id="boost_task.pool.scheduling.fifo"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.pool.scheduling.fifo">fifo</link>
+ </bridgehead>
+ <para>
+ First inserted pending <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ gets taken first.
+ </para>
+ <anchor id="boost_task.pool.scheduling.priority"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.pool.scheduling.priority">priority</link>
+ </bridgehead>
+ <para>
+ Each <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> is submitted to the pool with a priority
+ attribute. The type and ordering of the priority is user-defined.
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase> <phrase role="comment">// allow unlimited tasks to be queue in global-queue
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">priority</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="comment">// tasks with lower priority are scheduled first
+</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">,</phrase> <phrase role="comment">// thread-pool
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="identifier">some_fn</phrase><phrase role="special">),</phrase> <phrase role="comment">// task to be executed
+</phrase> <phrase role="number">5</phrase><phrase role="special">);</phrase> <phrase role="comment">// priority is 5
+</phrase>
+<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">,</phrase> <phrase role="comment">// thread-pool
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="identifier">another_fn</phrase><phrase role="special">),</phrase> <phrase role="comment">// task to be executed
+</phrase> <phrase role="number">3</phrase><phrase role="special">);</phrase> <phrase role="comment">// priority is 3
+</phrase></programlisting>
+ </para>
+ <para>
+ In this example the tasks get scheduled by the assigned integer (third argument
+ of <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">async</phrase><phrase role="special">()</phrase></code>).
+ The <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> with the lowest priority gets scheduled
+ first (taken by a <emphasis>worker-thread</emphasis>). The ordering can be
+ changed by the second argument of <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">priority</phrase></code>
+ (the default is <code><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">less</phrase><phrase role="special">&lt;</phrase> <phrase
+ role="identifier">Attr</phrase> <phrase role="special">&gt;</phrase></code>).
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">priority</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase><phrase role="special">,</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">greater</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="comment">// tasks with higher priority are scheduled first
+</phrase>
+<phrase role="special">&gt;</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ <anchor id="boost_task.pool.scheduling.smart"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.pool.scheduling.smart">smart</link>
+ </bridgehead>
+ <para>
+ Each inserted <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> is associated with an attribute. The
+ scheduler gets an put- and take-policy as template arguments. The corresponding
+ policy gets applied for each insertion and removal.
+ </para>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> provides <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">replace_oldest</phrase></code>
+ as put- policy and <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">take_oldest</phrase></code>
+ as take-policy. Both policies allow the replacement of older (pending) tasks
+ in the scheduler by new ones.
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</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">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">smart</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="keyword">int</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">less</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;,</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</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">task</phrase><phrase role="special">::</phrase><phrase role="identifier">take_oldest</phrase>
+ <phrase role="special">&gt;</phrase>
+ <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</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="special">...</phrase>
+
+ <phrase role="comment">// replaced by later task with same attribute == 2
+</phrase> <phrase role="comment">// if still pending in pool
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</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">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</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="number">2</phrase><phrase role="special">);</phrase> <phrase role="comment">// attribute is 2
+</phrase>
+ <phrase role="comment">// will replace previous pending task with attribute == 2
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</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">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase> <phrase role="number">5</phrase><phrase role="special">),</phrase>
+ <phrase role="number">2</phrase><phrase role="special">);</phrase> <phrase role="comment">// attribute is 2 too
+</phrase><phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.pool.pool_shutdown">
+ <title><link linkend="boost_task.pool.pool_shutdown"> Pool shutdown</link></title>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> allows to shutdown a <emphasis>thread-pool</emphasis>
+ explicitly via functions <code><phrase role="identifier">shutdown</phrase><phrase
+ role="special">()</phrase></code> and <code><phrase role="identifier">shutdown_now</phrase><phrase
+ role="special">()</phrase></code>. The destructor of the pool calls <code><phrase
+ role="identifier">shutdown</phrase><phrase role="special">()</phrase></code>
+ if not already done so that all <emphasis>worker-threads</emphasis> are joined
+ and the topic of <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2802.html">N2802</ulink>
+ should be addressed.
+ </para>
+ <anchor id="boost_task.pool.pool_shutdown.shutdown"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.pool.pool_shutdown.shutdown">Shutdown</link>
+ </bridgehead>
+ <para>
+ If <code><phrase role="identifier">shutdown</phrase><phrase role="special">()</phrase></code>
+ is called - the the pool is set the closed state and all <emphasis>worker-threads</emphasis>
+ are joined until all pending tasks are processed. No futher tasks can be
+ submitted.
+ </para>
+ <note>
+ <para>
+ The deconstructor calls <code><phrase role="identifier">shutdown</phrase><phrase
+ role="special">()</phrase></code> if the pool was not shutdown yet.
+ </para>
+ </note>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</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">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase>
+ <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</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="special">...</phrase>
+
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">,</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</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">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">,</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase> <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="identifier">pool</phrase><phrase role="special">.</phrase><phrase role="identifier">shutdown</phrase><phrase role="special">();</phrase>
+
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(10) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h1</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(5) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h2</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <anchor id="boost_task.pool.pool_shutdown.shutdown_immediatly"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.pool.pool_shutdown.shutdown_immediatly">Shutdown
+ immediatly</link>
+ </bridgehead>
+ <para>
+ The function <code><phrase role="identifier">shutdown_now</phrase><phrase
+ role="special">()</phrase></code> closes the pool, interrupts and then joins
+ all <emphasis>worker-threads</emphasis>. Pending tasks are unprocessed.
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</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">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase>
+ <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">pool_type</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</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="special">...</phrase>
+
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">,</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</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">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">,</phrase> <phrase role="comment">// asynchronous executor
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase> <phrase role="number">5</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_now</phrase><phrase role="special">();</phrase>
+
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(10) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h1</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase> <phrase role="comment">// may throw broken_task or task_interrupted
+</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(5) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h2</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase> <phrase role="comment">// may throw broken_task or task_interrupted
+</phrase><phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.pool.default_pool">
+ <title><link linkend="boost_task.pool.default_pool"> Default pool</link></title>
+ <para>
+ The library provides a default-pool accessible via <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">default_pool</phrase><phrase
+ role="special">()</phrase></code>. The function returns a reference to <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">fifo</phrase> <phrase role="special">&gt;</phrase> <phrase
+ role="special">&gt;</phrase></code>. The static instance of <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">default_pool</phrase></code> contains as many <emphasis>worker-threads</emphasis>
+ 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, queues unlimited amount of tasks and schedules the tasks in FIFO-order.
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</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">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="number">0</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="number">1</phrase><phrase role="special">;</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">k1</phrase><phrase role="special">(</phrase> <phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">k2</phrase><phrase role="special">(</phrase> <phrase role="number">0</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">2</phrase><phrase role="special">);</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase>
+ <phrase role="special">{</phrase>
+ <phrase role="keyword">long</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">(</phrase> <phrase role="identifier">k1</phrase><phrase role="special">);</phrase>
+ <phrase role="identifier">k1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">k1</phrase> <phrase role="special">+</phrase> <phrase role="identifier">k2</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">k2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">tmp</phrase><phrase role="special">;</phrase>
+ <phrase role="special">}</phrase>
+ <phrase role="keyword">return</phrase> <phrase role="identifier">k1</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;worker-threads running in default-pool == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">default_pool</phrase><phrase role="special">().</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h1</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">default_pool</phrase><phrase role="special">(),</phrase> <phrase role="comment">// asynchronous executor == default-pool
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</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">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h2</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">default_pool</phrase><phrase role="special">(),</phrase> <phrase role="comment">// asynchronous executor == default-pool
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="identifier">fibonacci_fn</phrase><phrase role="special">,</phrase> <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(10) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h1</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;fibonacci(5) == &quot;</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h2</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.pool.processor_binding">
+ <title><link linkend="boost_task.pool.processor_binding"> Processor binding</link></title>
+ <para>
+ For some applications it is convenient to bind the <emphasis>worker-threads</emphasis>
+ to processors/cores of the system. For this purpose <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">poolsize</phrase></code>
+ must not be given to the constructor so that a <emphasis>worker-thread</emphasis>
+ is created an bound the the core.
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">tp</phrase><phrase role="special">::</phrase><phrase role="identifier">fifo</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="special">&gt;</phrase> <phrase role="identifier">pool</phrase><phrase role="special">;</phrase> <phrase role="comment">// constructs thread-pool with worker-threads as hardware_concurrency() returns
+</phrase></programlisting>
+ </para>
+ <para>
+ The constructor takes additional arguments for the link_work_stealing[work-stealing
+ algorithm] and link_channel[high-] and link_channel[low-watermark] too.
+ </para>
+ <note>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> does provide this feature only
+ for Windows, Linux, AIX, HP-UX and Solaris.
+ </para>
+ </note>
+ </section>
+ <section id="boost_task.pool.work_stealing">
+ <title><link linkend="boost_task.pool.work_stealing"> Work-Stealing</link></title>
+ <para>
+ Traditional <emphasis>thread-pools</emphasis> do not scale because they use
+ a single global-queue protected by a global-lock. The frequency at which
+ <emphasis>worker-threads</emphasis> aquire the global-lock becomes a limiting
+ factor for the throughput if:
+ </para>
+ <itemizedlist>
+ <listitem>
+ the tasks become smaller
+ </listitem>
+ <listitem>
+ more processors are added
+ </listitem>
+ </itemizedlist>
+ <para>
+ A <emphasis>work-stealing</emphasis> 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
+ <emphasis>worker-thread</emphasis> owning the queue), but requires synchronization
+ from the <emphasis>public end</emphasis> (accessed by the other <emphasis>worker-threads</emphasis>).
+ Synchronization is necessary when the queue is sufficiently small that private
+ and public operations could conflict.
+ </para>
+ <para>
+ The pool contains one global-queue (<code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">bounded_channel</phrase></code>
+ or <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">unbounded_channel</phrase></code>) protected by a global-lock
+ and each <emphasis>worker-thread</emphasis> has its own private local worker-queue.
+ If work is enqueued by a <emphasis>worker-thread</emphasis> the <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> is stored in the worker queue. If
+ the work is enqueued by a application thread it goes into the global queue.
+ When <emphasis>worker-threads</emphasis> are looking for work, they have
+ following search order:
+ </para>
+ <itemizedlist>
+ <listitem>
+ look into the private worker-queue - tasks can be dequeued without locks
+ </listitem>
+ <listitem>
+ look in the global-queue - locks are used for synchronization
+ </listitem>
+ <listitem>
+ check other worker-queues ('stealing' tasks from private worker queues
+ of other <emphasis>worker-threads</emphasis>) - requires locks
+ </listitem>
+ </itemizedlist>
+ <para>
+ For a lot of recursively queued tasks (so called <emphasis>sub-tasks</emphasis>),
+ 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 <emphasis>worker-threads</emphasis> in FIFO order
+ (steals).
+ </para>
+ <itemizedlist>
+ <listitem>
+ There are chances that memory is still hot in the cache, if the tasks are
+ pushed in LIFO order into the private worker queue.
+ </listitem>
+ <listitem>
+ If a <emphasis>worker-thread</emphasis> 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 <emphasis>sub-tasks</emphasis>
+ 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 <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> also steals a (probably) larger
+ subtree of tasks unfolded if the stolen work item get executed. Since a
+ <emphasis>sub-task</emphasis> is just part of a larger <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase></code>,
+ we don’t need to worry about execution order.
+ </listitem>
+ </itemizedlist>
+ </section>
+ <para>
+ / 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
+ ]
+ </para>
+ <section id="boost_task.pool.forkjoin">
+ <title><link linkend="boost_task.pool.forkjoin"> Fork/Join</link></title>
+ <para>
+ Fork/Join algorithms are recursive divide-and-conquer algorithms which repeatedly
+ splitt into sub-tasks 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 new <emphasis>sub-tasks</emphasis> which can run
+ in parallel. The current <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ is not proceeded in the join operation until the forked <emphasis>sub-tasks</emphasis>
+ have completed. In the meantime the <emphasis>worker-thread</emphasis> executes
+ other tasks from its local worker-queue.
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">long</phrase> <phrase role="identifier">serial_fib</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase><phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="number">2</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">serial_fib</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="identifier">serial_fib</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="keyword">long</phrase> <phrase role="identifier">parallel_fib</phrase><phrase role="special">(</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">n</phrase><phrase role="special">,</phrase> <phrase role="keyword">long</phrase> <phrase role="identifier">cutof</phrase><phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">if</phrase> <phrase role="special">(</phrase> <phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">serial_fib</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="comment">// fork a sub-task calculating fibonacci(n-1)
+</phrase> <phrase role="identifier">h1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">as_sub_task</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">parallel_fib</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="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="comment">// fork a sub-task calculating fibonacci(n-2)
+</phrase> <phrase role="identifier">h2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">as_sub_task</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">parallel_fib</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="identifier">cutof</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="comment">// join the results of both sub-tasks
+</phrase> <phrase role="comment">// if one of the both sub-tasks is not ready
+</phrase> <phrase role="comment">// the worker-thread does not block, it executes other
+</phrase> <phrase role="comment">// task from its local-queue
+</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">h1</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">h2</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">void</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase> <phrase role="comment">// handle for fibonacci calculation
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">default_pool</phrase><phrase role="special">(),</phrase> <phrase role="comment">// access the default thread-pool
+</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase> <phrase role="comment">// calculate fibonacci number 10
+</phrase> <phrase role="identifier">parallel_fib</phrase><phrase role="special">,</phrase> <phrase role="comment">// for numbers &lt; 5 do inline recursive calculation
+</phrase> <phrase role="number">10</phrase><phrase role="special">,</phrase>
+ <phrase role="number">5</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">.</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ </section>
+ </section>
+ <section id="boost_task.as_sub_task">
+ <title><link linkend="boost_task.as_sub_task"> Execute as sub-task</link></title>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">as_sub_task</phrase></code>
+ is a convenient way to execute a <emphasis>sub-task</emphasis>. If the parent
+ task is executed inside a <emphasis>thread-pool</emphasis> the <emphasis>sub-task</emphasis>
+ is put into the local-queue of the <emphasis>worker-thread</emphasis> in the
+ other case the <emphasis>sub-task</emphasis> will be executed in a new thread.
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">long</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">as_sub_task</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">fibonacci</phrase><phrase role="special">,</phrase>
+ <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase> <phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ <para>
+ is equivalent to:
+ </para>
+ <para>
+
+<programlisting><phrase role="keyword">if</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">runs_in_pool</phrase><phrase role="special">()</phrase> <phrase role="special">)</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="comment">// put the sub-task into worker-threads local-queue
+</phrase><phrase role="special">}</phrase>
+<phrase role="keyword">else</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">new_thread</phrase><phrase role="special">(),</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">make_task</phrase><phrase role="special">(...)</phrase> <phrase role="special">);</phrase>
+<phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.utilities">
+ <title><link linkend="boost_task.utilities"> Utilities</link></title>
+ <para>
+ <emphasis role="bold">Boost.Task</emphasis> provides some free-functions which
+ can be used inside a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code> to access some informations (like if
+ the <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ runs in a <emphasis>thread-pool</emphasis>).
+ </para>
+ <anchor id="boost_task.utilities.reschedule_until"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.utilities.reschedule_until">reschedule_until</link>
+ </bridgehead>
+ <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">Pred</phrase> <phrase role="keyword">const</phrase><phrase
+ role="special">&amp;)</phrase></code> allows to synchronize the task with other
+ asynchronous events without blocking the <emphasis>worker-threads</emphasis>
+ (bool Pred::operator()() must not block). The current task will be rescheduled
+ until the passed predicate becomes true.
+ </para>
+ <anchor id="boost_task.utilities.get_pool"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.utilities.get_pool">get_pool</link>
+ </bridgehead>
+ <para>
+ The pool in which the current code (<code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code>) is executed 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_pool</phrase><phrase
+ role="special">()</phrase></code>. If hte code is not executed by a <emphasis>worker-thread</emphasis>
+ an assertion is raised.
+ </para>
+ <anchor id="boost_task.utilities.runs_in_pool"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.utilities.runs_in_pool">runs_in_pool</link>
+ </bridgehead>
+ <para>
+ In order to check if the current code is executed in a <emphasis>thread-pool</emphasis>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">runs_in_pool</phrase><phrase role="special">()</phrase></code>
+ should be used.
+ </para>
+ <anchor id="boost_task.utilities.worker_id"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.utilities.worker_id">worker_id</link>
+ </bridgehead>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">this_task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">worker_id</phrase><phrase role="special">()</phrase></code>
+ returns the <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">thread</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">id</phrase></code> of the <emphasis>worker-thread</emphasis>
+ executing the current <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase></code>.
+ </para>
+ <anchor id="boost_task.utilities.delay"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.utilities.delay">delay</link>
+ </bridgehead>
+ <para>
+ The execution of a <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ can be delayed for a time-duration or until a specific time-point with <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">delay</phrase><phrase role="special">()</phrase></code>.
+ </para>
+ <anchor id="boost_task.utilities.yield"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.utilities.yield">yield</link>
+ </bridgehead>
+ <para>
+ If a <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ detects that it would bould block it can yield itself with <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">yield</phrase><phrase role="special">()</phrase></code>
+ so that the <emphasis>worker-thread</emphasis> can execute another <code><phrase
+ role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase></code> in
+ the meantime.
+ </para>
+ <anchor id="boost_task.utilities.interrupt"/>
+ <bridgehead renderas="sect3">
+ <link linkend="boost_task.utilities.interrupt">interrupt</link>
+ </bridgehead>
+ <para>
+ A <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase></code>
+ can interrupt itself via <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">this_task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">interrupt</phrase><phrase
+ role="special">()</phrase></code>.
+ </para>
+ </section>
+ <section id="boost_task.meta_functions">
+ <title><link linkend="boost_task.meta_functions"> Meta functions</link></title>
+ <para>
+ If the <emphasis>thread-pool</emphasis> supports attributes (like priorities)
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">has_attribute</phrase></code>
+ evaluates to <code><phrase role="keyword">true</phrase></code> at compile-time
+ (derived from boost::mpl::bool_). The type of the attribute is determined by
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">attribute_type</phrase></code>.
+ </para>
+ <para>
+
+<programlisting><phrase role="identifier">typdef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">unbounded_channel</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">priority</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">int</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="comment">// pool with priority scheduling; integer as priority type
+</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">pool_type</phrase><phrase role="special">;</phrase>
+
+<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">boolalpha</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">has_attribute</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">&quot;\n&quot;</phrase><phrase role="special">;</phrase>
+<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="keyword">typeid</phrase><phrase role="special">(</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">task</phrase><phrase role="special">::</phrase><phrase role="identifier">attribute_type</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">pool_type</phrase> <phrase role="special">&gt;::</phrase><phrase role="identifier">type</phrase><phrase role="special">).</phrase><phrase role="identifier">name</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.reference">
+ <title><link linkend="boost_task.reference"> Reference</link></title>
+ <section id="boost_task.reference.task">
+ <title><link linkend="boost_task.reference.task"> Class template <code><phrase
+ role="identifier">task</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="keyword">class</phrase> <phrase role="identifier">task</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="identifier">task</phrase><phrase role="special">(</phrase> <phrase role="identifier">Fn</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">const</phrase> <phrase role="identifier">id</phrase> <phrase role="identifier">get_id</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+
+ <phrase role="identifier">shared_future</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">get_future</phrase><phrase role="special">();</phrase>
+
+ <phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="comment">// throw();
+</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()()</phrase> <phrase role="comment">// throw();
+</phrase><phrase role="special">}</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.task.constructor">
+ <title><link linkend="boost_task.reference.task.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Fn</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">task</phrase><phrase role="special">(</phrase> <phrase role="identifier">Fn</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">fn</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">tp</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">&lt;</phrase> <phrase role="identifier">R</phrase>
+ <phrase role="special">&gt;</phrase></code> from a function object
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.task.get_id">
+ <title><link linkend="boost_task.reference.task.get_id"> Member function
+ <code><phrase role="identifier">get_id</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">const</phrase> <phrase role="identifier">id</phrase> <phrase role="identifier">get_id</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns task identifier
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.task.get_future">
+ <title><link linkend="boost_task.reference.task.get_future"> Member function
+ <code><phrase role="identifier">get_future</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">shared_future</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">get_future</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns a future assiciated with the task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ ???
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.task.swap">
+ <title><link linkend="boost_task.reference.task.swap"> Member function <code><phrase
+ role="identifier">swap</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ swaps the task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.task.operator">
+ <title><link linkend="boost_task.reference.task.operator"> Member function
+ <code><phrase role="keyword">operator</phrase><phrase role="special">()()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ executes tasks internal function object
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_task.reference.handle">
+ <title><link linkend="boost_task.reference.handle"> Class template <code><phrase
+ role="identifier">handle</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">handle</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="keyword">class</phrase> <phrase role="identifier">handle</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="identifier">handle</phrase><phrase role="special">();</phrase>
+
+ <phrase role="keyword">const</phrase> <phrase role="identifier">id</phrase> <phrase role="identifier">get_id</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</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_until</phrase><phrase role="special">(</phrase> <phrase role="identifier">system_time</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Duration</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait_for</phrase><phrase role="special">(</phrase> <phrase role="identifier">Duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">rel_time</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">interruption_requested</phrase><phrase role="special">();</phrase>
+
+ <phrase role="identifier">R</phrase> <phrase role="identifier">get</phrase><phrase role="special">();</phrase>
+
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">is_ready</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">has_value</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">has_exception</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">void</phrase> <phrase role="identifier">wait</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+
+ <phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase> <phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.handle.constructor">
+ <title><link linkend="boost_task.reference.handle.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="identifier">handle</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ constructs an empty (invalid) handle
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.get_id">
+ <title><link linkend="boost_task.reference.handle.get_id"> Member function
+ <code><phrase role="identifier">get_id</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">const</phrase> <phrase role="identifier">id</phrase> <phrase role="identifier">get_id</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns identifier of the associated task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.interruption_requested">
+ <title><link linkend="boost_task.reference.handle.interruption_requested">
+ Member function <code><phrase role="identifier">interruption_requested</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">interruption_requested</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ checks if interruption is already requested
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.interrupt">
+ <title><link linkend="boost_task.reference.handle.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>
+ requests task interruption; doesn not block (immediatly returns)
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ ???
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.interrupt_and_wait">
+ <title><link linkend="boost_task.reference.handle.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>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ requests task interruption and blocks until worker-thread stops task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ ???
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.interrupt_and_wait_until">
+ <title><link linkend="boost_task.reference.handle.interrupt_and_wait_until">
+ Member function <code><phrase role="identifier">interrupt_and_wait_until</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait_until</phrase><phrase role="special">(</phrase> <phrase role="identifier">system_time</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ requests task interruption and blocks until worker-thread stops task
+ or time-point elapsed
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ ???
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.interrupt_and_wait_for">
+ <title><link linkend="boost_task.reference.handle.interrupt_and_wait_for">
+ Member function <code><phrase role="identifier">interrupt_and_wait_for</phrase><phrase
+ role="special">()</phrase></code></link></title>
+<programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Duration</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="keyword">void</phrase> <phrase role="identifier">interrupt_and_wait_for</phrase><phrase role="special">(</phrase> <phrase role="identifier">Duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">rel_time</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ requests task interruption and blocks until worker-thread stops task
+ or time-duration elapsed
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ ???
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.get">
+ <title><link linkend="boost_task.reference.handle.get"> Member function
+ <code><phrase role="identifier">get</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="identifier">R</phrase> <phrase role="identifier">get</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ requests the result
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ task_interrupted, task_uninialized
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.wait">
+ <title><link linkend="boost_task.reference.handle.wait"> Member function
+ <code><phrase role="identifier">wait</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">wait</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ blocks caller until task is done
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ task_interrupted, task_uninialized
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.is_ready">
+ <title><link linkend="boost_task.reference.handle.is_ready"> Member function
+ <code><phrase role="identifier">is_ready</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">is_ready</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ checks if task is done
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.has_value">
+ <title><link linkend="boost_task.reference.handle.has_value"> Member function
+ <code><phrase role="identifier">has_value</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">has_value</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ checks if task is done and a result value is set
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.has_exception">
+ <title><link linkend="boost_task.reference.handle.has_exception"> Member
+ function <code><phrase role="identifier">has_exception</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">has_exception</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ checks if task is done and an exception is set
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.handle.swap">
+ <title><link linkend="boost_task.reference.handle.swap"> Member function
+ <code><phrase role="identifier">swap</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase> <phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ swapps handle
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_task.reference.async">
+ <title><link linkend="boost_task.reference.async"> Function <code><phrase role="identifier">async</phrase><phrase
+ role="special">()</phrase></code></link></title>
+ <section id="boost_task.reference.async.async_default">
+ <title><link linkend="boost_task.reference.async.async_default"> Templated
+ non-member function <code><phrase role="identifier">async</phrase><phrase
+ role="special">(</phrase> <phrase role="identifier">AE</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">R</phrase> <phrase role="special">&gt;)</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">async</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">AE</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">async</phrase><phrase role="special">(</phrase> <phrase role="identifier">AE</phrase> <phrase role="identifier">ae</phrase><phrase role="special">,</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ executes task in an asyncrounous executer and returns a handle associated
+ with the task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.async.async_pool">
+ <title><link linkend="boost_task.reference.async.async_pool"> Templated non-member
+ function <code><phrase role="identifier">async</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">pool</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">Channel</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="special">&amp;,</phrase> <phrase role="identifier">task</phrase><phrase
+ role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase
+ role="special">&gt;)</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">async</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Channel</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">async</phrase><phrase role="special">(</phrase> <phrase role="identifier">pool</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Channel</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">ae</phrase><phrase role="special">,</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ executes task in a thread-pool and returns a handle associated with
+ the task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.async.async_pool_attr">
+ <title><link linkend="boost_task.reference.async.async_pool_attr"> Templated
+ non-member function <code><phrase role="identifier">async</phrase><phrase
+ role="special">(</phrase> <phrase role="identifier">pool</phrase><phrase
+ role="special">&lt;</phrase> <phrase role="identifier">Channel</phrase>
+ <phrase role="special">&gt;</phrase> <phrase role="special">&amp;,</phrase>
+ <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">R</phrase> <phrase role="special">&gt;,</phrase>
+ <phrase role="identifier">Attr</phrase><phrase role="special">)</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">async</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Channel</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">async</phrase><phrase role="special">(</phrase> <phrase role="identifier">pool</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Channel</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">ae</phrase><phrase role="special">,</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase role="identifier">attr</phrase><phrase role="special">);</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ executes atrributed task in a thread-pool and returns a handle associated
+ with the task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_task.reference.own_thread">
+ <title><link linkend="boost_task.reference.own_thread"> Class <code><phrase
+ role="identifier">own_thread</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">async</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">struct</phrase> <phrase role="identifier">own_thread</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.own_thread.operator">
+ <title><link linkend="boost_task.reference.own_thread.operator"> Member function
+ <code><phrase role="keyword">operator</phrase><phrase role="special">()(</phrase>
+ <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="identifier">t</phrase><phrase role="special">)</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ executes task in the current thread an returns an handle associated
+ with the task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_task.reference.new_thread">
+ <title><link linkend="boost_task.reference.new_thread"> Class <code><phrase
+ role="identifier">new_thread</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">async</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">struct</phrase> <phrase role="identifier">new_thread</phrase>
+<phrase role="special">{</phrase>
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.new_thread.operator">
+ <title><link linkend="boost_task.reference.new_thread.operator"> Member function
+ <code><phrase role="keyword">operator</phrase><phrase role="special">()(</phrase>
+ <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="identifier">t</phrase><phrase role="special">)</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ executes task in a new thread an returns an handle associated with
+ the task
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_task.reference.static_pool">
+ <title><link linkend="boost_task.reference.static_pool"> Class template <code><phrase
+ role="identifier">static_pool</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Channel</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="keyword">class</phrase> <phrase role="identifier">static_pool</phrase> <phrase role="special">:</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">noncopyable</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">);</phrase>
+
+ <phrase role="special">~</phrase><phrase role="identifier">static_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">void</phrase> <phrase role="identifier">shutdown_now</phrase><phrase role="special">();</phrase>
+
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">closed</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
+ <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">pending</phrase><phrase role="special">();</phrase>
+
+ <phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">);</phrase>
+ <phrase role="keyword">const</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">();</phrase>
+ <phrase role="keyword">void</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">&gt;</phrase>
+ <phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">t</phrase><phrase role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">attr</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.static_pool.constructor_unbounded_channel_hw">
+ <title><link linkend="boost_task.reference.static_pool.constructor_unbounded_channel_hw">
+ Constructor (unbounded channel)</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">static_pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ operating system provides functionality for processor pining
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ constructs a pool - for each processor a worker-thread is created and
+ bound to one processor - global-queue can queue an unlimited number
+ of tasks
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</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">task</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 unbounded-channel is used
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.constructor_unbounded_channel">
+ <title><link linkend="boost_task.reference.static_pool.constructor_unbounded_channel">
+ Constructor (unbounded channel)</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">static_pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">microseconds</phrase><phrase role="special">(</phrase> <phrase role="number">10</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ constructs a pool containing psize worker-threads - global-queue can
+ queue an unlimited number of tasks
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</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">task</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 unbounded-channel is used
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.constructor_bounded_channel_hw">
+ <title><link linkend="boost_task.reference.static_pool.constructor_bounded_channel_hw">
+ Constructor (bounded channel)</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">static_pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ operating system provides functionality for processor pining
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ constructs a pool - for each processor a worker-thread is created and
+ bound to one processor - global-queue can only queue a limited number
+ of tasks
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</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">task</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">task</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 bounded-channel is used.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.constructor_bounded_channel">
+ <title><link linkend="boost_task.reference.static_pool.constructor_bounded_channel">
+ Constructor (bounded channel)</link></title>
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">static_pool</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">poolsize</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">psize</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">,</phrase>
+ <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">time_duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">asleep</phrase> <phrase role="special">=</phrase> <phrase role="identifier">posix_time</phrase><phrase role="special">::</phrase><phrase role="identifier">milliseconds</phrase><phrase role="special">(</phrase> <phrase role="number">100</phrase><phrase role="special">),</phrase>
+ <phrase role="identifier">scanns</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">scns</phrase> <phrase role="special">=</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="number">20</phrase><phrase role="special">)</phrase> <phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ constructs a pool containing psize worker-threads - global-queue can
+ only queue a limited number of tasks
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</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">task</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">task</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 bounded-channel is used
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.destructor">
+ <title><link linkend="boost_task.reference.static_pool.destructor"> Destructor</link></title>
+
+<programlisting><phrase role="special">~</phrase><phrase role="identifier">static_pool</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ calls <code><phrase role="special">:</phrase><phrase role="identifier">shutdown</phrase><phrase
+ role="special">()</phrase></code> if not already called
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.size">
+ <title><link linkend="boost_task.reference.static_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_task.reference.static_pool.active">
+ <title><link linkend="boost_task.reference.static_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 task)
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.idle">
+ <title><link linkend="boost_task.reference.static_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 task).
+ </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_task.reference.static_pool.shutdown">
+ <title><link linkend="boost_task.reference.static_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>
+ deactivates the channel and joins all worker-threads - the pool is
+ closed
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ all pending tasks are processed
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.shutdown_now">
+ <title><link linkend="boost_task.reference.static_pool.shutdown_now"> Member
+ function <code><phrase role="identifier">shutdown_now</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">shutdown_now</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ deactivates the channel, send interruption request to all worker-threads
+ and joins them - the pool is closed
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Notes:</term>
+ <listitem>
+ <para>
+ pending tasks are not processed but returned
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.losed">
+ <title><link linkend="boost_task.reference.static_pool.losed"> Member function
+ <code><phrase role="identifier">closed</phrase><phrase role="special">()</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">bool</phrase> <phrase role="identifier">closed</phrase><phrase role="special">()</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ queries if the pool is closed (pool is shutdown)
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.clear">
+ <title><link linkend="boost_task.reference.static_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 tasks from the channel
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.empty">
+ <title><link linkend="boost_task.reference.static_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 channel is empty
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.pending">
+ <title><link linkend="boost_task.reference.static_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 tasks are pending (still unprocessed) in the global-queue
+ (channel)
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.get_upper_bound">
+ <title><link linkend="boost_task.reference.static_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 bounded-channel
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns the upper bound of the bounded-channel
+ </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 bounded-channel is used
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.set_upper_bound">
+ <title><link linkend="boost_task.reference.static_pool.set_upper_bound">
+ Member function <code><phrase role="identifier">upper_bound</phrase><phrase
+ role="special">(</phrase> <phrase role="identifier">high_watermark</phrase>
+ <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase>
+ <phrase role="identifier">hwm</phrase><phrase role="special">)</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">upper_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">high_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">hwm</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ channel is of type bounded-channel
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ sets the upper bound of the bounded-channel
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Postconditions:</term>
+ <listitem>
+ <para>
+ <code><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase
+ role="identifier">upper_bound</phrase><phrase role="special">()</phrase>
+ <phrase role="special">==</phrase> <phrase role="identifier">hwm</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</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 bounded-channel is used
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.get_lower_bound">
+ <title><link linkend="boost_task.reference.static_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 bounded-channel
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns the lower bound of the bounded-channel
+ </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 bounded-channel is used
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.set_lower_bound">
+ <title><link linkend="boost_task.reference.static_pool.set_lower_bound">
+ Member function <code><phrase role="identifier">lower_bound</phrase><phrase
+ role="special">(</phrase> <phrase role="identifier">low_watermark</phrase>
+ <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase>
+ <phrase role="identifier">lwm</phrase><phrase role="special">)</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">lower_bound</phrase><phrase role="special">(</phrase> <phrase role="identifier">low_watermark</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">lwm</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ channel is of type bounded-channel
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ sets the lower bound of the bounded-channel
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Postconditions:</term>
+ <listitem>
+ <para>
+ <code><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase
+ role="identifier">lower_bound</phrase><phrase role="special">()</phrase>
+ <phrase role="special">==</phrase> <phrase role="identifier">lwm</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</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 bounded-channel is used
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.submit">
+ <title><link linkend="boost_task.reference.static_pool.submit"> Member function
+ <code><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase
+ role="special">&amp;</phrase> <phrase role="identifier">act</phrase><phrase
+ role="special">)</phrase></code></link></title>
+<programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">t</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ has_attribute&lt; pool &gt;::value == false &amp;&amp; ! closed()
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ submits an task to the pool and returns an associated handle
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task_rejected</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.static_pool.submit_attr">
+ <title><link linkend="boost_task.reference.static_pool.submit_attr"> Member
+ function <code><phrase role="identifier">submit</phrase><phrase role="special">(</phrase>
+ <phrase role="identifier">Act</phrase> <phrase role="keyword">const</phrase><phrase
+ role="special">&amp;</phrase> <phrase role="identifier">act</phrase><phrase
+ role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase
+ role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase
+ role="identifier">attr</phrase><phrase role="special">)</phrase></code></link></title>
+
+<programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">R</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Attr</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">handle</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">submit</phrase><phrase role="special">(</phrase> <phrase role="identifier">task</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">R</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">t</phrase><phrase role="special">,</phrase> <phrase role="identifier">Attr</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">attr</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ has_attribute&lt; pool &gt;::value == true &amp;&amp; ! closed()
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ submits an task to the pool and returns an associated handle - task
+ 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">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task_rejected</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_task.reference.utility">
+ <title><link linkend="boost_task.reference.utility"> Utilities</link></title>
+ <section id="boost_task.reference.utility.reschedule_until">
+ <title><link linkend="boost_task.reference.utility.reschedule_until"> Non-member
+ function <code><phrase role="identifier">reschedule_until</phrase><phrase
+ role="special">()</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">utility</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pred</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="keyword">void</phrase> <phrase role="identifier">reschedule_until</phrase><phrase role="special">(</phrase> <phrase role="identifier">Pred</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ reschedules current task until passed callable predicate 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_task.reference.utility.get_pool">
+ <title><link linkend="boost_task.reference.utility.get_pool"> Non-member
+ function <code><phrase role="identifier">get_pool</phrase><phrase role="special">()</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">utility</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="identifier">Pool</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">get_pool</phrase><phrase role="special">()</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns reference to the thread-pool where the current worker thread
+ is executed
+ </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_task.reference.utility.runs_in_pool">
+ <title><link linkend="boost_task.reference.utility.runs_in_pool"> Non-member
+ function <code><phrase role="identifier">runs_in_pool</phrase><phrase role="special">()</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">utility</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">bool</phrase> <phrase role="identifier">runs_in_pool</phrase><phrase role="special">()</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns true if the current task is executed in a thread-pool
+ </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_task.reference.utility.worker_id">
+ <title><link linkend="boost_task.reference.utility.worker_id"> Non-member
+ function <code><phrase role="identifier">worker_id</phrase><phrase role="special">()</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">utility</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="identifier">id</phrase> <phrase role="identifier">worker_id</phrase><phrase role="special">()</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns returns the thread-id of the worker-thread
+ </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_task.reference.utility.delay">
+ <title><link linkend="boost_task.reference.utility.delay"> Non-member function
+ <code><phrase role="identifier">delay</phrase><phrase role="special">()</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">utility</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">delay</phrase><phrase role="special">(</phrase> <phrase role="identifier">system_time</phrase> <phrase role="identifier">abs_time</phrase><phrase role="special">)</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Duration</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="keyword">void</phrase> <phrase role="identifier">delay</phrase><phrase role="special">(</phrase> <phrase role="identifier">Duration</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">rel_time</phrase><phrase role="special">)</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ delays the execution of the current task so that the worker-thread
+ can process another task in the meantime
+ </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_task.reference.utility.yield">
+ <title><link linkend="boost_task.reference.utility.yield"> Non-member function
+ <code><phrase role="identifier">yield</phrase><phrase role="special">()</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">utility</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">yield</phrase><phrase role="special">()</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ yields the current task so that the worker-threadcan process another
+ task in the meantime
+ </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_task.reference.utility.interrupt">
+ <title><link linkend="boost_task.reference.utility.interrupt"> Non-member
+ function <code><phrase role="identifier">interrupt</phrase><phrase role="special">()</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">utility</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">void</phrase> <phrase role="identifier">interrupt</phrase><phrase role="special">()</phrase>
+</programlisting>
+ </para>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ task can request interruption for itself
+ </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>
+ <section id="boost_task.reference.has_attribute">
+ <title><link linkend="boost_task.reference.has_attribute"> Meta function <code><phrase
+ role="identifier">has_attribute</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">meta</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="keyword">struct</phrase> <phrase role="identifier">has_attribute</phrase> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">mpl</phrase><phrase role="special">::</phrase><phrase role="identifier">bool_</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">is_same</phrase><phrase role="special">&lt;</phrase>
+ <phrase role="identifier">detail</phrase><phrase role="special">::</phrase><phrase role="identifier">has_priority</phrase><phrase role="special">,</phrase>
+ <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase><phrase role="special">::</phrase><phrase role="identifier">scheduler_type</phrase><phrase role="special">::</phrase><phrase role="identifier">priority_tag_type</phrase>
+ <phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase>
+<phrase role="special">&gt;</phrase>
+<phrase role="special">{};</phrase>
+</programlisting>
+ </para>
+ </section>
+ <section id="boost_task.reference.attribute_type">
+ <title><link linkend="boost_task.reference.attribute_type"> Meta function
+ <code><phrase role="identifier">attribute_type</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">meta</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Pool</phrase> <phrase role="special">&gt;</phrase>
+<phrase role="keyword">struct</phrase> <phrase role="identifier">attribute_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>
+ </para>
+ </section>
+ <section id="boost_task.reference.invalid_poolsize">
+ <title><link linkend="boost_task.reference.invalid_poolsize"> Class <code><phrase
+ role="identifier">invalid_poolsize</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_poolsize</phrase> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">invalid_poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.invalid_poolsize.constructor">
+ <title><link linkend="boost_task.reference.invalid_poolsize.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="identifier">invalid_poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</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_task.reference.invalid_scanns">
+ <title><link linkend="boost_task.reference.invalid_scanns"> Class <code><phrase
+ role="identifier">invalid_scanns</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_scanns</phrase> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">invalid_scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.invalid_scanns.constructor">
+ <title><link linkend="boost_task.reference.invalid_scanns.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="identifier">invalid_scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</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_task.reference.invalid_timeduration">
+ <title><link linkend="boost_task.reference.invalid_timeduration"> Class <code><phrase
+ role="identifier">invalid_timeduration</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_timeduration</phrase> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">invalid_timeduration</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.invalid_timeduration.constructor">
+ <title><link linkend="boost_task.reference.invalid_timeduration.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="identifier">invalid_timeduration</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</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_task.reference.invalid_watermark">
+ <title><link linkend="boost_task.reference.invalid_watermark"> Class <code><phrase
+ role="identifier">invalid_watermark</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">invalid_watermark</phrase> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">invalid_argument</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">invalid_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.invalid_watermark.constructor">
+ <title><link linkend="boost_task.reference.invalid_watermark.constructor">
+ Constructor</link></title>
+<programlisting><phrase role="identifier">invalid_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</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_task.reference.task_rejected">
+ <title><link linkend="boost_task.reference.task_rejected"> Class <code><phrase
+ role="identifier">task_rejected</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">exceptions</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">task_rejected</phrase> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">runtime_error</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="identifier">task_rejected</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">);</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.task_rejected.constructor">
+ <title><link linkend="boost_task.reference.task_rejected.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="identifier">task_rejected</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">msg</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ Constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</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_task.reference.poolsize">
+ <title><link linkend="boost_task.reference.poolsize"> Class <code><phrase role="identifier">poolsize</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">poolsize</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">poolsize</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.poolsize.constructor">
+ <title><link linkend="boost_task.reference.poolsize.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">poolsize</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ value &gt; 0
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">poolsize</phrase></code>
+ instance
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Postconditions:</term>
+ <listitem>
+ <para>
+ operator std::size_t () &gt; 0
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_poolsize</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.poolsize.operator">
+ <title><link linkend="boost_task.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>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns the value
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ <section id="boost_task.reference.high_watermark">
+ <title><link linkend="boost_task.reference.high_watermark"> Class <code><phrase
+ role="identifier">high_watermark</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">watermark</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">high_watermark</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">high_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.high_watermark.constructor">
+ <title><link linkend="boost_task.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">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_watermark</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.high_watermark.operator">
+ <title><link linkend="boost_task.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>
+</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_task.reference.low_watermark">
+ <title><link linkend="boost_task.reference.low_watermark"> Class <code><phrase
+ role="identifier">low_watermark</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">watermark</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">low_watermark</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">low_watermark</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.low_watermark.constructor">
+ <title><link linkend="boost_task.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">task</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">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_watermark</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.low_watermark.operator">
+ <title><link linkend="boost_task.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>
+</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_task.reference.scanns">
+ <title><link linkend="boost_task.reference.scanns"> Class <code><phrase role="identifier">scanns</phrase></code></link></title>
+ <para>
+
+<programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">task</phrase><phrase role="special">/</phrase><phrase role="identifier">scanns</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
+
+<phrase role="keyword">class</phrase> <phrase role="identifier">scanns</phrase>
+<phrase role="special">{</phrase>
+<phrase role="keyword">public</phrase><phrase role="special">:</phrase>
+ <phrase role="keyword">explicit</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
+
+ <phrase role="keyword">operator</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
+<phrase role="special">};</phrase>
+</programlisting>
+ </para>
+ <section id="boost_task.reference.scanns.constructor">
+ <title><link linkend="boost_task.reference.scanns.constructor"> Constructor</link></title>
+
+<programlisting><phrase role="keyword">explicit</phrase> <phrase role="identifier">scanns</phrase><phrase role="special">(</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">size_t</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Preconditions:</term>
+ <listitem>
+ <para>
+ value &gt; 0
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ constructs a <code><phrase role="identifier">boost</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">task</phrase><phrase
+ role="special">::</phrase><phrase role="identifier">scanns</phrase></code>
+ instance
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Postconditions:</term>
+ <listitem>
+ <para>
+ operator std::size_t () &gt; 0
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">invalid_poolsize</phrase></code>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ <section id="boost_task.reference.scanns.operator">
+ <title><link linkend="boost_task.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>
+</programlisting>
+ <variablelist>
+ <title></title> <varlistentry><term>Effects:</term>
+ <listitem>
+ <para>
+ returns the value
+ </para>
+ </listitem>
+ </varlistentry> <varlistentry><term>Throws:</term>
+ <listitem>
+ <para>
+ Nothing
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
+ </section>
+ </section>
+ <section id="boost_task.appendices">
+ <title><link linkend="boost_task.appendices">Appendices</link></title>
+ <section id="boost_task.appendices.todo">
+ <title><link linkend="boost_task.appendices.todo"> Appendix A: Future development</link></title>
+ <anchor id="boost_task.appendices.todo.dynamic_thread_pool"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.appendices.todo.dynamic_thread_pool">Dynamic thread-pool</link>
+ </bridgehead>
+ <itemizedlist>
+ <listitem>
+ <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">dynamic_pool</phrase></code> adds or removes <emphasis>worker-threads</emphasis>
+ from the <emphasis>thread-pool</emphasis> depending on the work-load (undersubscription/
+ oversubscription).
+ </listitem>
+ </itemizedlist>
+ <anchor id="boost_task.appendices.todo.communication_and_synchronisation_abstractions"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.appendices.todo.communication_and_synchronisation_abstractions">Communication
+ and synchronisation abstractions</link>
+ </bridgehead>
+ <itemizedlist>
+ <listitem>
+ <emphasis role="bold">Event variable</emphasis>: 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.
+ </listitem>
+ <listitem>
+ <emphasis role="bold">Buffer</emphasis>: 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. When the
+ buffer is full, the task 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.
+ </listitem>
+ <listitem>
+ <emphasis role="bold">Multicast</emphasis>: 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.
+ </listitem>
+ <listitem>
+ <emphasis role="bold">Rendezvous</emphasis>: 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.
+ </listitem>
+ <listitem>
+ <emphasis role="bold">Protected resource</emphasis>: A protected resource
+ is a passive entity that controls access to the internal states (to the
+ controled real resources).
+ </listitem>
+ <listitem>
+ <emphasis role="bold">Task groups</emphasis>: A task group defines a graph
+ of interdependent tasks that can mostly be run in parallel. The tasks in
+ the group have dependencies or communicate with each other.
+ </listitem>
+ </itemizedlist>
+ <anchor id="boost_task.appendices.todo.interdepended_task"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.appendices.todo.interdepended_task">Interdepended
+ task</link>
+ </bridgehead>
+ <itemizedlist>
+ <listitem>
+ With special support of concurrence and synchronisation abstractions interdepended
+ tasks work in <emphasis>thread-pools</emphasis> (using context switching/fibers).
+ </listitem>
+ </itemizedlist>
+ <anchor id="boost_task.appendices.todo.support_of_explicit_processor_bindig"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.appendices.todo.support_of_explicit_processor_bindig">Support
+ of explicit processor bindig</link>
+ </bridgehead>
+ <itemizedlist>
+ <listitem>
+ <emphasis>asynchronous-executors</emphasis> related to a <emphasis>thread-pool</emphasis>
+ (like <code><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">task</phrase><phrase role="special">::</phrase><phrase
+ role="identifier">default_pool</phrase></code>) could support explicit
+ processor binding.
+ </listitem>
+ </itemizedlist>
+ <anchor id="boost_task.appendices.todo.optimizations"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.appendices.todo.optimizations">Optimizations</link>
+ </bridgehead>
+ <itemizedlist>
+ <listitem>
+ two-lock-queue as global queue in <emphasis>thread-pool</emphasis>
+ </listitem>
+ <listitem>
+ maybe lock-free-queue as global queue too (how to provide the scheduling
+ policies fifo, priority, smart?)
+ </listitem>
+ </itemizedlist>
+ <anchor id="boost_task.appendices.todo.actor_framework"/>
+ <bridgehead renderas="sect4">
+ <link linkend="boost_task.appendices.todo.actor_framework">Actor framework</link>
+ </bridgehead>
+ <itemizedlist>
+ <listitem>
+ framework support of communication and synchronisation between tasks
+ </listitem>
+ <listitem>
+ so called actors provide the required mechanisms
+ </listitem>
+ <listitem>
+ for a detailed explanation read Micorsoft proposal of <ulink url="http://msdn.microsoft.com/en-us/devlabs/dd795202.aspx">Axum</ulink>
+ </listitem>
+ </itemizedlist>
+ </section>
+ <section id="boost_task.appendices.acknowledgements">
+ <title><link linkend="boost_task.appendices.acknowledgements"> Appendix B:
+ Acknowledgments</link></title>
+ <para>
+ 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.
+ </para>
+ </section>
+ </section>
+</library>

Modified: sandbox/task/libs/task/doc/channel.qbk
==============================================================================
--- sandbox/task/libs/task/doc/channel.qbk (original)
+++ sandbox/task/libs/task/doc/channel.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -8,12 +8,13 @@
 
 [section:channel Channel]
 
-The channel synchronizes the access between non-pool threads (application threads) and __worker_threads__ and implements a queuing policy (limitation of queued _tasks__).
+The channel synchronizes the access between non-pool threads (application threads) and __worker_threads__ and implements
+a queuing policy (limitation of queued tasks).
 
 
 [heading __bounded_channel__]
 
-__bounded_channel__ contains a single lock in order to synchronize access to the queue. The number of pending __tasks__ is limited in order to prevent resource exhaustion.
+__bounded_channel__ contains a single lock in order to synchronize access to the queue. The number of pending tasks is limited in order to prevent resource exhaustion.
 For this purpose a high- and low-watermark has to be passed at construction.
 __hwm__ sets the maximum of pending tasks. If this limited is reached all threads which submit a task will be set to sleep (blocked). If it is equal to __lwm__ everytime a
 sleeping producer thread will be woken up and puts its task if one worker thread has taken a task from the channel.
@@ -23,8 +24,8 @@
 
 [heading __unbounded_channel__]
 
-__unbounded_channel__ contains a single lock in order to synchronize access to the queue. An unlimited number of __tasks__ can be queued into this channel.
-The insertion of an __task__ will never block. If the channel becomes empty __worker_threads__ will be set to sleep until new __tasks__ are enqueued.
+__unbounded_channel__ contains a single lock in order to synchronize access to the queue. An unlimited number of tasks can be queued into this channel.
+The insertion of an __task__ will never block. If the channel becomes empty __worker_threads__ will be set to sleep until new tasks are enqueued.
 
 
 [endsect]

Modified: sandbox/task/libs/task/doc/default_pool.qbk
==============================================================================
--- sandbox/task/libs/task/doc/default_pool.qbk (original)
+++ sandbox/task/libs/task/doc/default_pool.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -8,8 +8,9 @@
 
 [section:default_pool Default pool]
 
-The library provides a default-pool accessible via __fn_default_pool__. The function returns a reference to __full_default_pool__. The static instance of __default_pool__ contains as many __worker_threads__ as
-__hardware_concurrency__ returns, queues unlimited amount of __tasks__ and schedules the __tasks__ in FIFO-order.
+The library provides a default-pool accessible via __fn_default_pool__. The function returns a reference to
+__full_default_pool__. The static instance of __default_pool__ contains as many __worker_threads__ as
+__hardware_concurrency__ returns, queues unlimited amount of tasks and schedules the tasks in FIFO-order.
 
 
 ``

Deleted: sandbox/task/libs/task/doc/description.qbk
==============================================================================
--- sandbox/task/libs/task/doc/description.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
+++ (empty file)
@@ -1,18 +0,0 @@
-[/
- Copyright Oliver Kowalke 2009.
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-]
-
-
-[section:description Description]
-
-[include task.qbk]
-[include async_completion_token.qbk]
-[include async_executor.qbk]
-[include utilities.qbk]
-[include meta_functions.qbk]
-
-
-[endsect]

Added: sandbox/task/libs/task/doc/fork_join.qbk
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/fork_join.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,65 @@
+/
+ 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:forkjoin Fork/Join]
+
+Fork/Join algorithms are recursive divide-and-conquer algorithms which repeatedly splitt into sub-tasks until they become small
+enough to solve using simple, short sequential methods, so that they run in parallel on multiple cores.
+
+The fork operation creates new __sub_tasks__ which can run in parallel. The current __task__ is not proceeded in the join operation
+until the forked __sub_tasks__ have completed. In the meantime the __worker_thread__ executes other tasks from its local worker-queue.
+
+``
+ 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
+ {
+ // fork a sub-task calculating fibonacci(n-1)
+ h1 = boost::task::async(
+ boost::task::as_sub_task(),
+ boost::task::make_task(
+ parallel_fib,
+ n - 1,
+ cutof) );
+ // fork a sub-task calculating fibonacci(n-2)
+ h2 = boost::task::async(
+ boost::task::as_sub_task(),
+ boost::task::make_task(
+ parallel_fib,
+ n - 2,
+ cutof) );
+ // join the results of both sub-tasks
+ // if one of the both sub-tasks is not ready
+ // the worker-thread does not block, it executes other
+ // task from its local-queue
+ return h1.get() + h2.get();
+ }
+ }
+
+ void main()
+ {
+ boost::task::handle< long > h( // handle for fibonacci calculation
+ boost::task::async(
+ boost::task::default_pool(), // access the default thread-pool
+ boost::task::make_task( // calculate fibonacci number 10
+ parallel_fib, // for numbers < 5 do inline recursive calculation
+ 10,
+ 5) ) );
+ std::cout << h.get() << std::endl;
+ }
+``
+
+
+[endsect]

Deleted: sandbox/task/libs/task/doc/forkjoin.qbk
==============================================================================
--- sandbox/task/libs/task/doc/forkjoin.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
+++ (empty file)
@@ -1,65 +0,0 @@
-/
- Copyright Oliver Kowalke 2009.
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt
-]
-
-
-[section:forkjoin Fork/Join]
-
-Fork/Join algorithms are recursive divide-and-conquer algorithms which repeatedly splitt __sub_taskss__ until they become small enough to solve using simple, short sequential methods,
-so that they run in parallel on multiple cores.
-
-The fork operation creates new __sub_tasks__ which can run in parallel. The current __task__ is not proceeded in the join operation until the forked __sub_tasks__ have completed.
-In the meantime the __worker_thread__ executes other __tasks__ from its local worker-queue.
-
-``
- 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
- {
- // fork a sub-task calculating fibonacci(n-1)
- h1 = boost::task::async(
- boost::task::as_sub_task(),
- boost::task::make_task(
- parallel_fib,
- n - 1,
- cutof) );
- // fork a sub-task calculating fibonacci(n-2)
- h2 = boost::task::async(
- boost::task::as_sub_task(),
- boost::task::make_task(
- parallel_fib,
- n - 2,
- cutof) );
- // join the results of both sub-tasks
- // if one of the both sub-tasks is not ready
- // the worker-thread does not block, it executes other
- // task from its local-queue
- return h1.get() + h2.get();
- }
- }
-
- void main()
- {
- boost::task::handle< long > h( // handle for fibonacci calculation
- boost::task::async(
- boost::task::default_pool(), // access the default thread-pool
- boost::task::make_task( // calculate fibonacci number 10
- parallel_fib, // for numbers < 5 do inline recursive calculation
- 10,
- 5) ) );
- std::cout << h.get() << std::endl;
- }
-``
-
-
-[endsect]

Modified: sandbox/task/libs/task/doc/handle.qbk
==============================================================================
--- sandbox/task/libs/task/doc/handle.qbk (original)
+++ sandbox/task/libs/task/doc/handle.qbk 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -8,10 +8,14 @@
 
 [section:handle Handle]
 
+The __act__ dispatches tasks in response to the completion of asynchronous operations. __act__ uniquely identifies
+the task and state necessary to process the result of the operation [footnote see [@http://www.cs.wustl.edu/~schmidt/PDF/ACT.pdf
+'Asynchronous Completion Token'], Douglas Schmidt].
+
 __handle__ represents an __act__. It will be returned by __fn_async__ and is associated with the submitted __task__.
 
 
-[heading:act_interface Asynchronous completion token interface]
+[heading Asynchronous completion token interface]
 
 __handle__ implements an interface in order to check the state of computation and result transfer
 
@@ -71,7 +75,7 @@
         }
 ``
 
-[heading:task_interruption Task interruption]
+[heading Task interruption]
 
 * __fn_interrupt__: interrupt __task__ and return immediately
 

Added: sandbox/task/libs/task/doc/html/boost_task/appendices.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/appendices.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,161 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Appendices</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="reference.html" title="Reference">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="reference.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a>
+</div>
+<div class="section" title="Appendices">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.appendices"></a><a class="link" href="appendices.html" title="Appendices">Appendices</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"> Appendix A: Future development</span></dt>
+<dt><span class="section"><a href="appendices.html#boost_task.appendices.acknowledgements"> Appendix B:
+ Acknowledgments</a></span></dt>
+</dl></div>
+<div class="section" title="Appendix A: Future development">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.appendices.todo"></a><a class="link" href="appendices.html#boost_task.appendices.todo" title="Appendix A: Future development"> Appendix A: Future development</a>
+</h3></div></div></div>
+<a name="boost_task.appendices.todo.dynamic_thread_pool"></a><h5>
+<a name="id598832"></a>
+ <a class="link" href="appendices.html#boost_task.appendices.todo.dynamic_thread_pool">Dynamic thread-pool</a>
+ </h5>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
+<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">dynamic_pool</span></code> adds or removes <span class="emphasis"><em>worker-threads</em></span>
+ from the <span class="emphasis"><em>thread-pool</em></span> depending on the work-load (undersubscription/
+ oversubscription).
+ </li></ul></div>
+<a name="boost_task.appendices.todo.communication_and_synchronisation_abstractions"></a><h5>
+<a name="id598896"></a>
+ <a class="link" href="appendices.html#boost_task.appendices.todo.communication_and_synchronisation_abstractions">Communication
+ and synchronisation abstractions</a>
+ </h5>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+<span class="bold"><strong>Event variable</strong></span>: 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.
+ </li>
+<li class="listitem">
+<span class="bold"><strong>Buffer</strong></span>: 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. When the
+ buffer is full, the task 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.
+ </li>
+<li class="listitem">
+<span class="bold"><strong>Multicast</strong></span>: 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.
+ </li>
+<li class="listitem">
+<span class="bold"><strong>Rendezvous</strong></span>: 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.
+ </li>
+<li class="listitem">
+<span class="bold"><strong>Protected resource</strong></span>: A protected resource
+ is a passive entity that controls access to the internal states (to the
+ controled real resources).
+ </li>
+<li class="listitem">
+<span class="bold"><strong>Task groups</strong></span>: A task group defines a graph
+ of interdependent tasks that can mostly be run in parallel. The tasks in
+ the group have dependencies or communicate with each other.
+ </li>
+</ul></div>
+<a name="boost_task.appendices.todo.interdepended_task"></a><h5>
+<a name="id598986"></a>
+ <a class="link" href="appendices.html#boost_task.appendices.todo.interdepended_task">Interdepended
+ task</a>
+ </h5>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
+ With special support of concurrence and synchronisation abstractions interdepended
+ tasks work in <span class="emphasis"><em>thread-pools</em></span> (using context switching/fibers).
+ </li></ul></div>
+<a name="boost_task.appendices.todo.support_of_explicit_processor_bindig"></a><h5>
+<a name="id599017"></a>
+ <a class="link" href="appendices.html#boost_task.appendices.todo.support_of_explicit_processor_bindig">Support
+ of explicit processor bindig</a>
+ </h5>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
+<span class="emphasis"><em>asynchronous-executors</em></span> related to a <span class="emphasis"><em>thread-pool</em></span>
+ (like <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span></code>) could support explicit
+ processor binding.
+ </li></ul></div>
+<a name="boost_task.appendices.todo.optimizations"></a><h5>
+<a name="id599080"></a>
+ <a class="link" href="appendices.html#boost_task.appendices.todo.optimizations">Optimizations</a>
+ </h5>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ two-lock-queue as global queue in <span class="emphasis"><em>thread-pool</em></span>
+</li>
+<li class="listitem">
+ maybe lock-free-queue as global queue too (how to provide the scheduling
+ policies fifo, priority, smart?)
+ </li>
+</ul></div>
+<a name="boost_task.appendices.todo.actor_framework"></a><h5>
+<a name="id599114"></a>
+ <a class="link" href="appendices.html#boost_task.appendices.todo.actor_framework">Actor framework</a>
+ </h5>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ framework support of communication and synchronisation between tasks
+ </li>
+<li class="listitem">
+ so called actors provide the required mechanisms
+ </li>
+<li class="listitem">
+ for a detailed explanation read Micorsoft proposal of Axum
+</li>
+</ul></div>
+</div>
+<div class="section" title="Appendix B: Acknowledgments">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.appendices.acknowledgements"></a><a class="link" href="appendices.html#boost_task.appendices.acknowledgements" title="Appendix B: Acknowledgments"> Appendix B:
+ Acknowledgments</a>
+</h3></div></div></div>
+<p>
+ 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.
+ </p>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="reference.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/as_sub_task.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/as_sub_task.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,81 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Execute as sub-task</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="pool.html" title="Thread-pool">
+<link rel="next" href="utilities.html" title="Utilities">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="pool.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="utilities.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Execute as sub-task">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.as_sub_task"></a><a class="link" href="as_sub_task.html" title="Execute as sub-task"> Execute as sub-task</a>
+</h2></div></div></div>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span></code>
+ is a convenient way to execute a <span class="emphasis"><em>sub-task</em></span>. If the parent
+ task is executed inside a <span class="emphasis"><em>thread-pool</em></span> the <span class="emphasis"><em>sub-task</em></span>
+ is put into the local-queue of the <span class="emphasis"><em>worker-thread</em></span> in the
+ other case the <span class="emphasis"><em>sub-task</em></span> will be executed in a new thread.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">fibonacci</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+<p>
+ is equivalent to:
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">if</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">runs_in_pool</span><span class="special">()</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="comment">// put the sub-task into worker-threads local-queue
+</span><span class="special">}</span>
+<span class="keyword">else</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(...)</span> <span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="pool.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="utilities.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/async_completion_token.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/async_completion_token.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,226 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Asynchronous completion token</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="callable.html" title="Callable">
+<link rel="next" href="async_executor.html" title="Asynchronous executor">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="callable.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="async_executor.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Asynchronous completion token">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.async_completion_token"></a><a class="link" href="async_completion_token.html" title="Asynchronous completion token"> Asynchronous completion
+ token</a>
+</h2></div></div></div>
+<div class="toc"><dl><dt><span class="section"> Handle</span></dt></dl></div>
+<p>
+ The <span class="emphasis"><em>asynchronous-completion-token</em></span> dispatches processing
+ actions (<span class="underline">_tasks</span>_) in response to the
+ completion of asynchronous operations. <span class="emphasis"><em>asynchronous-completion-token</em></span>
+ uniquely identifies the task and state necessary to process the result of the
+ operation
+ <sup>[<a name="id638673" href="#ftn.id638673" class="footnote">3</a>]</sup>
+ .
+ </p>
+<div class="section" title="Handle">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.async_completion_token.handle"></a><a class="link" href="async_completion_token.html#boost_task.async_completion_token.handle" title="Handle"> Handle</a>
+</h3></div></div></div>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span></code> represents an <span class="emphasis"><em>asynchronous-completion-token</em></span>.
+ It will be returned by <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code> and is associated with the submitted <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>.
+ </p>
+<a name="boost_task.async_completion_token.handle._act_interface_asynchronous_completion_token_interface"></a><h5>
+<a name="id638788"></a>
+ <a class="link" href="async_completion_token.html#boost_task.async_completion_token.handle._act_interface_asynchronous_completion_token_interface">:act_interface
+ Asynchronous completion token interface</a>
+ </h5>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span></code> implements an interface in order
+ to check the state of computation and result transfer
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code>:
+ return id of the associated task-id
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">is_ready</span><span class="special">()</span></code>:
+ test if result is set
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">has_value</span><span class="special">()</span></code>:
+ test if value-result is set
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">has_exception</span><span class="special">()</span></code>:
+ test if exception-result is set
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">get</span><span class="special">()</span></code>:
+ return value-result
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">wait</span><span class="special">()</span></code>:
+ wait until result is set
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">wait_for</span><span class="special">()</span></code>:
+ wait until result is set or time-duration has elapsed
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">wait_until</span><span class="special">()</span></code>:
+ wait until result ist set or time-point has elapsed
+ </li>
+</ul></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_requested</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// check if interruption was requested
+</span> <span class="keyword">return</span><span class="special">;</span>
+
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">fibonacci</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"id == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"is ready == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">is_ready</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">h</span><span class="special">.</span><span class="identifier">wait</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"has value == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">has_value</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"has exception == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">has_exception</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<a name="boost_task.async_completion_token.handle._task_interruption_task_interruption"></a><h5>
+<a name="id639994"></a>
+ <a class="link" href="async_completion_token.html#boost_task.async_completion_token.handle._task_interruption_task_interruption">:task_interruption
+ Task interruption</a>
+ </h5>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">interrupt</span><span class="special">()</span></code>:
+ interrupt <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> and return immediately
+ </li>
+<li class="listitem">
+ __fn_interrupt_and<span class="underline">wait</span>_: interrupt
+ and wait until <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> was removed from <span class="emphasis"><em>worker-thread</em></span>
+</li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">interrupt_and_wait_for</span><span class="special">()</span></code>: interrupt and wait until <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> was removed from <span class="emphasis"><em>worker-thread</em></span>
+ or time duration has elapsed
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">interrupt_and_wait_until</span><span class="special">()</span></code>: interrupt and wait until <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> was removed from <span class="emphasis"><em>worker-thread</em></span>
+ or time point has elapsed
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_requested</span><span class="special">()</span></code>:
+ return bool if interruption was requested
+ </li>
+</ul></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">cooperative</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_requested</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// check if interruption was requested
+</span> <span class="keyword">return</span><span class="special">;</span>
+
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// get handle associated with the task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// task, to be executed asynchronously
+</span> <span class="identifier">cooperative</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">h</span><span class="special">.</span><span class="identifier">interrupt_and_wait</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"id == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"is ready == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">is_ready</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"has value == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">has_value</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"has exception == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">has_exception</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// throws boost::task::task_interrupted
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a name="ftn.id638673" href="#id638673" class="para">3</a>] </sup>
+ see <a href="http://www.cs.wustl.edu/~schmidt/PDF/ACT.pdf" target="_top">'Asynchronous
+ Completion Token'</a>, Douglas Schmidt
+ </p></div>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="callable.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="async_executor.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/async_executor.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/async_executor.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,944 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Asynchronous executor</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="handle.html" title="Handle">
+<link rel="next" href="utilities.html" title="Utilities">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="handle.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="utilities.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Asynchronous executor">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.async_executor"></a><a class="link" href="async_executor.html" title="Asynchronous executor"> Asynchronous executor</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"> boost::task::own_thread</span></dt>
+<dt><span class="section"> boost::task::new_thread</span></dt>
+<dt><span class="section"> Thread pool</span></dt>
+<dt><span class="section"> boost::task::as_sub_task</span></dt>
+</dl></div>
+<p>
+ In contrast to synchronous methods asynchronous methods do not block the program
+ flow when a time consuming operation is executed. The application continues
+ executing the current context and when the result of the asynchronous method
+ is required the <span class="emphasis"><em>asynchronous-completion-token</em></span> can be used.
+ </p>
+<p>
+ An <span class="emphasis"><em>asynchronous-executor</em></span> executes a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> asynchronously and provides a link<span class="underline">handle(</span><span class="underline">act</span>_)
+ to manage the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>.
+ </p>
+<div class="section" title="boost::task::own_thread">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.async_executor.own_thread"></a><a class="link" href="async_executor.html#boost_task.async_executor.own_thread" title="boost::task::own_thread"> <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">own_thread</span></code></a>
+</h3></div></div></div>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">own_thread</span></code> executes the task in the current
+ thread (synchronous execution - concerns of N2802
+ do not aply).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">own_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">fibonacci</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section" title="boost::task::new_thread">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.async_executor.new_thread"></a><a class="link" href="async_executor.html#boost_task.async_executor.new_thread" title="boost::task::new_thread"> <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span></code></a>
+</h3></div></div></div>
+<p>
+ _new<span class="underline">thread</span>_ creates a new <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code> and executes the task in this thread
+ (asynchronous). The created thread gets joined by handle.
+ </p>
+<div class="caution" title="Caution"><table border="0" summary="Caution">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../doc/html/images/caution.png"></td>
+<th align="left">Caution</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Always store the returned <span class="emphasis"><em>asynchronous-completion-token</em></span>
+ in a variable because <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span></code>
+ joins the thread in its destructor (if the last reference gets out of scope).
+ </p></td></tr>
+</table></div>
+<p>
+ The topic of N2802
+ should be addressed.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">fibonacci</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ In the example below both <code class="computeroutput"><span class="identifier">a_function</span></code>
+ and <code class="computeroutput"><span class="identifier">another_function</span></code> are
+ executed synchron (see link_own<span class="underline">thread[</span>_own<span class="underline">thread</span>_] for synchronous execution)!
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">a_function</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">another_function</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section" title="Thread pool">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.async_executor.pool"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool" title="Thread pool"> Thread pool</a>
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"> boost::task::static_pool</span></dt>
+<dt><span class="section"> Channel</span></dt>
+<dt><span class="section"> Scheduling</span></dt>
+<dt><span class="section"><a href="async_executor.html#boost_task.async_executor.pool.pool_shutdown"> Pool
+ shutdown</a></span></dt>
+<dt><span class="section"><a href="async_executor.html#boost_task.async_executor.pool.default_pool"> Default
+ pool</a></span></dt>
+<dt><span class="section"><a href="async_executor.html#boost_task.async_executor.pool.processor_binding">
+ Processor binding</a></span></dt>
+<dt><span class="section"> Work-Stealing</span></dt>
+<dt><span class="section"> Fork/Join</span></dt>
+</dl></div>
+<p>
+ Instead of creating a new thread and quickly throwing it away after the task
+ is done, the overhead related to thread creation and destruction can be avoided
+ by running the <span class="emphasis"><em>work-items</em></span> on a <span class="emphasis"><em>thread-pool</em></span>
+ (reusing an existing <span class="underline">_worker</span><span class="underline">thread</span>_ instead).
+ </p>
+<p>
+ A <span class="emphasis"><em>thread-pool</em></span> maintains a queue (or queues) of <span class="emphasis"><em>work-items</em></span>
+ to be done, and a pool of <span class="emphasis"><em>worker-threads</em></span> which execute
+ <span class="emphasis"><em>work-items</em></span> from the queue(s).
+ </p>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> provides <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code> with support of executing an <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> in <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span></code>
+ (using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">()</span></code>):
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">echo</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">msg</span><span class="special">)</span>
+<span class="special">{</span> <span class="keyword">return</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">echo</span><span class="special">,</span>
+ <span class="string">"Hello World!"</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ and a custom <span class="emphasis"><em>thread-pool</em></span> (passing pool instance as an
+ argument to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code>):
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">echo</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">msg</span><span class="special">)</span>
+<span class="special">{</span> <span class="keyword">return</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">fifo</span>
+ <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">5</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">echo</span><span class="special">,</span>
+ <span class="string">"Hello World!"</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ .
+ </p>
+<div class="important" title="Important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../doc/html/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ <span class="underline">_tasks</span>_ should not be too small (performance
+ overhead dominates) and avoid blocking <span class="underline">_tasks</span>_
+ <sup>[<a name="id665925" href="#ftn.id665925" class="footnote">4</a>]</sup>
+ .
+ </p></td></tr>
+</table></div>
+<div class="section" title="boost::task::static_pool">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_task.async_executor.pool.static_pool"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool.static_pool" title="boost::task::static_pool"> <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span></code></a>
+</h4></div></div></div>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> provides <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span></code>
+ - which contains an fixed set of pre-forked <span class="emphasis"><em>worker-threads</em></span>
+ (the size of the pool doesn't change during its lifetime).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">_static_pool</span><span class="special">&lt;</span> <span class="comment">// pool type
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span> <span class="comment">// queuing policy (unbounded_channel, bounded_channel)
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">fifo</span> <span class="comment">// scheduling policy (fifo, priority, smart)
+</span> <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">6</span><span class="special">),</span> <span class="comment">// pool with 6 pre-forked worker-threads
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span> <span class="number">50</span><span class="special">),</span> <span class="comment">// time to sleep if no work-item available
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">scanns</span><span class="special">(</span> <span class="number">10</span><span class="special">)</span> <span class="special">);</span> <span class="comment">// iterations over local-queues before sleep
+</span></pre>
+<p>
+ </p>
+<p>
+ The first argument of the constructor specifies how many <span class="emphasis"><em>worker-threads</em></span>
+ the pool will contain. The second and third argument are used by the link_work<span class="underline">stealing[</span>_work<span class="underline">stealing</span>_]
+ algorithm.
+ </p>
+<div class="note" title="Note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ If <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">bounded_channel</span></code> is used as queuing
+ policy the constructor has two additional arguments .
+ </p></td></tr>
+</table></div>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span></code> provides functionality to
+ check the status of the pool - <code class="computeroutput"><span class="identifier">close</span><span class="special">()</span></code> returns true when the pool was shutdown
+ and <code class="computeroutput"><span class="identifier">active</span><span class="special">()</span></code>
+ as well as <span class="underline">_fn</span><span class="underline">idle</span>_
+ returning how many <span class="emphasis"><em>worker-threads</em></span> are active (executing
+ a task) or idle. The size of the pool can be accessed over <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>.
+ </p>
+<p>
+ For infomational pruposes <code class="computeroutput"><span class="identifier">empty</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">pending</span><span class="special">()()</span></code> can be used in order to know if the
+ global task-queue is empty or how many <span class="underline">_tasks</span>_
+ are waiting for execution. __fn<span class="underline">clear</span>_
+ removes all <span class="underline">_tasks</span>_ from the global-queue.
+ </p>
+<div class="note" title="Note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ <code class="computeroutput"><span class="identifier">pending</span><span class="special">()()</span></code>
+ does not count <span class="underline">_tasks</span>_ in the local-queues
+ of the <span class="emphasis"><em>worker-threads</em></span>.
+ </p></td></tr>
+</table></div>
+</div>
+<div class="section" title="Channel">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_task.async_executor.pool.channel"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool.channel" title="Channel"> Channel</a>
+</h4></div></div></div>
+<p>
+ The channel synchronizes the access between non-pool threads (application
+ threads) and <span class="emphasis"><em>worker-threads</em></span> and implements a queuing
+ policy (limitation of queued <span class="underline">tasks</span>_).
+ </p>
+<a name="boost_task.async_executor.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__bounded_channel__phrase___code_"></a><h6>
+<a name="id666571"></a>
+ <a class="link" href="async_executor.html#boost_task.async_executor.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__bounded_channel__phrase___code_"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">bounded_channel</span></code></a>
+ </h6>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">bounded_channel</span></code> contains a single lock
+ in order to synchronize access to the queue. The number of pending <span class="underline">_tasks</span>_ is limited in order to prevent resource
+ exhaustion. For this purpose a high- and low-watermark has to be passed
+ at construction. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">high_watermark</span></code>
+ sets the maximum of pending tasks. If this limited is reached all threads
+ which submit a task will be set to sleep (blocked). If it is equal to
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">low_watermark</span></code> everytime a sleeping producer
+ thread will be woken up and puts its task if one worker thread has taken
+ a task from the channel. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">low_watermark</span></code>
+ sets the threshold when blocked threads get woken up. If it is less than
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">high_watermark</span></code> all sleeping producer
+ threads will be woken up if the amount of pending tasks reaches <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">low_watermark</span></code>.
+ </p>
+<a name="boost_task.async_executor.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__unbounded_channel__phrase___code_"></a><h6>
+<a name="id666810"></a>
+ <a class="link" href="async_executor.html#boost_task.async_executor.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__unbounded_channel__phrase___code_"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span></code></a>
+ </h6>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span></code> contains a single lock
+ in order to synchronize access to the queue. An unlimited number of <span class="underline">_tasks</span>_ can be queued into this channel. The
+ insertion of an <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> will never block. If the channel
+ becomes empty <span class="emphasis"><em>worker-threads</em></span> will be set to sleep
+ until new <span class="underline">_tasks</span>_ are enqueued.
+ </p>
+</div>
+<div class="section" title="Scheduling">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_task.async_executor.pool.scheduling"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool.scheduling" title="Scheduling"> Scheduling</a>
+</h4></div></div></div>
+<p>
+ The scheduling policy determines how <span class="underline">_tasks</span>_
+ are scheduled inside the <span class="underline">_channel</span>_.
+ </p>
+<a name="boost_task.async_executor.pool.scheduling.fifo"></a><h6>
+<a name="id666972"></a>
+ <a class="link" href="async_executor.html#boost_task.async_executor.pool.scheduling.fifo">fifo</a>
+ </h6>
+<p>
+ First inserted pending <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ gets taken first.
+ </p>
+<a name="boost_task.async_executor.pool.scheduling.priority"></a><h6>
+<a name="id667024"></a>
+ <a class="link" href="async_executor.html#boost_task.async_executor.pool.scheduling.priority">priority</a>
+ </h6>
+<p>
+ Each <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> is submitted to the pool with a
+ priority attribute. The type and ordering of the priority is user-defined.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span> <span class="comment">// allow unlimited tasks to be queue in global-queue
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">priority</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="comment">// tasks with lower priority are scheduled first
+</span><span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">5</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// thread-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">some_fn</span><span class="special">),</span> <span class="comment">// task to be executed
+</span> <span class="number">5</span><span class="special">);</span> <span class="comment">// priority is 5
+</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// thread-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">another_fn</span><span class="special">),</span> <span class="comment">// task to be executed
+</span> <span class="number">3</span><span class="special">);</span> <span class="comment">// priority is 3
+</span></pre>
+<p>
+ </p>
+<p>
+ In this example the <span class="underline">_tasks</span>_ get scheduled
+ by the assigned integer (third argument of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code>). The <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ with the lowest priority gets scheduled first (taken by a <span class="emphasis"><em>worker-thread</em></span>).
+ The ordering can be changed by the second argument of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">priority</span></code>
+ (the default is <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span> <span class="identifier">Attr</span> <span class="special">&gt;</span></code>).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">priority</span><span class="special">&lt;</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">greater</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="comment">// tasks with higher priority are scheduled first
+</span>
+<span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">5</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+<a name="boost_task.async_executor.pool.scheduling.smart"></a><h6>
+<a name="id667817"></a>
+ <a class="link" href="async_executor.html#boost_task.async_executor.pool.scheduling.smart">smart</a>
+ </h6>
+<p>
+ Each inserted <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> is associated with an attribute.
+ The scheduler gets an put- and take-policy as template arguments. The corresponding
+ policy gets applied for each insertion and removal.
+ </p>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> provides <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">replace_oldest</span></code>
+ as put- policy and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">take_oldest</span></code>
+ as take-policy. Both policies allow the replacement of older (pending)
+ <span class="underline">_tasks</span>_ in the scheduler by new ones.
+ </p>
+<pre class="programlisting"><span class="comment">// creates a pool with unbounded channel
+</span><span class="comment">// tasks are processed depending on the associated attributed
+</span><span class="comment">// oldest tasks with the same attributed pending in the channel
+</span><span class="comment">// will be replaced by the new task
+</span><span class="comment">// this example would execute add( 1, 2) and add( 5, 6)
+</span><span class="comment">// add( 2, 3) is removed (if pending when add( 5, 6) is submitted)
+</span></pre>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci_fn</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">smart</span><span class="special">&lt;</span>
+ <span class="keyword">int</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">replace_oldest</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">take_oldest</span>
+ <span class="special">&gt;</span>
+ <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">1</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="special">...</span>
+
+ <span class="comment">// replaced by later task with same attribute == 2
+</span> <span class="comment">// if still pending in pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">10</span><span class="special">),</span>
+ <span class="number">2</span><span class="special">);</span> <span class="comment">// attribute is 2
+</span>
+ <span class="comment">// will replace previous pending task with attribute == 2
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">5</span><span class="special">),</span>
+ <span class="number">2</span><span class="special">);</span> <span class="comment">// attribute is 2 too
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section" title="Pool shutdown">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_task.async_executor.pool.pool_shutdown"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool.pool_shutdown" title="Pool shutdown"> Pool
+ shutdown</a>
+</h4></div></div></div>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> allows to shutdown a <span class="emphasis"><em>thread-pool</em></span>
+ explicitly via functions <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">shutdown_now</span><span class="special">()</span></code>. The destructor of the pool calls <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code>
+ if not already done so that all <span class="emphasis"><em>worker-threads</em></span> are
+ joined and the topic of N2802
+ should be addressed.
+ </p>
+<a name="boost_task.async_executor.pool.pool_shutdown.shutdown"></a><h6>
+<a name="id668957"></a>
+ <a class="link" href="async_executor.html#boost_task.async_executor.pool.pool_shutdown.shutdown">Shutdown</a>
+ </h6>
+<p>
+ If <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code>
+ is called - the the pool is set the closed state and all <span class="emphasis"><em>worker-threads</em></span>
+ are joined until all pending <span class="underline">_tasks</span>_
+ are processed. No futher <span class="underline">_tasks</span>_
+ can be submitted.
+ </p>
+<div class="note" title="Note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ The deconstructor calls <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code> if the pool was not shutdown yet.
+ </p></td></tr>
+</table></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci_fn</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">fifo</span>
+ <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">1</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="special">...</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">5</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">shutdown</span><span class="special">();</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h1</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(5) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h2</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<a name="boost_task.async_executor.pool.pool_shutdown.shutdown_immediatly"></a><h6>
+<a name="id670068"></a>
+ <a class="link" href="async_executor.html#boost_task.async_executor.pool.pool_shutdown.shutdown_immediatly">Shutdown
+ immediatly</a>
+ </h6>
+<p>
+ The function <code class="computeroutput"><span class="identifier">shutdown_now</span><span class="special">()</span></code> closes the pool, interrupts and then
+ joins all <span class="emphasis"><em>worker-threads</em></span>. Pending <span class="underline">_tasks</span>_
+ are unprocessed.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci_fn</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">fifo</span>
+ <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">1</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="special">...</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">5</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">shutdown_now</span><span class="special">();</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h1</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span> <span class="comment">// may throw broken_task or task_interrupted
+</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(5) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h2</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// may throw broken_task or task_interrupted
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section" title="Default pool">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_task.async_executor.pool.default_pool"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool.default_pool" title="Default pool"> Default
+ pool</a>
+</h4></div></div></div>
+<p>
+ The library provides a default-pool accessible via <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">()</span></code>. The function returns a reference to
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">&gt;</span> <span class="special">&gt;</span></code>. The static instance of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span></code> contains as many <span class="emphasis"><em>worker-threads</em></span>
+ as <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">hardware_concurrency</span><span class="special">()</span></code>
+ returns, queues unlimited amount of <span class="underline">_tasks</span>_
+ and schedules the <span class="underline">_tasks</span>_ in FIFO-order.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci_fn</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"worker-threads running in default-pool == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">().</span><span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">(),</span> <span class="comment">// asynchronous executor == default-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">(),</span> <span class="comment">// asynchronous executor == default-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">5</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h1</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(5) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h2</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section" title="Processor binding">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_task.async_executor.pool.processor_binding"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool.processor_binding" title="Processor binding">
+ Processor binding</a>
+</h4></div></div></div>
+<p>
+ For some applications it is convenient to bind the <span class="emphasis"><em>worker-threads</em></span>
+ to processors/cores of the system. For this purpose <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span></code>
+ must not be given to the constructor so that a <span class="emphasis"><em>worker-thread</em></span>
+ is created an bound the the core.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tp</span><span class="special">::</span><span class="identifier">fifo</span> <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">;</span> <span class="comment">// constructs thread-pool with worker-threads as hardware_concurrency() returns
+</span></pre>
+<p>
+ </p>
+<p>
+ The constructor takes additional arguments for the link_work_stealing[work-stealing
+ algorithm] and link_channel[high-] and link_channel[low-watermark] too.
+ </p>
+<div class="note" title="Note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ <span class="bold"><strong>Boost.Task</strong></span> does only provide this feature
+ for Windows, Linux, AIX, HP-UX and Solaris.
+ </p></td></tr>
+</table></div>
+</div>
+<div class="section" title="Work-Stealing">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_task.async_executor.pool.work_stealing"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool.work_stealing" title="Work-Stealing"> Work-Stealing</a>
+</h4></div></div></div>
+<p>
+ The most important aspect of <span class="emphasis"><em>work-stealing</em></span> is that
+ it enables fast enqueue and dequeue in the typical case, often requiring
+ no synchronization at all. This virtually eliminates a large part of the
+ overhead of QUWI, when working with child tasks. We still do need to allocate
+ memory for the Task itself, and for the work-stealing queue, but like the
+ improvements to the FIFO queue these data structures have been optimized
+ for good GC performance. Parent tasks are fast; child tasks are much faster.
+ </p>
+<p>
+ Traditional <span class="emphasis"><em>thread-pools</em></span> do not scale because they
+ use a single global-queue protected by a global-lock. The frequency at
+ which <span class="emphasis"><em>worker-threads</em></span> aquire the global-lock becomes
+ a limiting factor for the throughput if:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ the <span class="underline">_tasks</span>_ become smaller
+ </li>
+<li class="listitem">
+ more processors are added
+ </li>
+</ul></div>
+<p>
+ A <span class="emphasis"><em>work-stealing</em></span> algorithm can be used to solve this
+ problem. It uses a special kind of queue which has two ends, and allows
+ lock-free pushes and pops from the <span class="emphasis"><em>private end</em></span> (accessed
+ by the <span class="emphasis"><em>worker-thread</em></span> owning the queue), but requires
+ synchronization from the <span class="emphasis"><em>public end</em></span> (accessed by the
+ other <span class="emphasis"><em>worker-threads</em></span>). Synchronization is necessary
+ when the queue is sufficiently small that private and public operations
+ could conflict.
+ </p>
+<p>
+ The pool contains one global-queue (<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">bounded_channel</span></code>
+ or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span></code>) protected by a global-lock
+ and each <span class="emphasis"><em>worker-thread</em></span> has its own private local worker-queue.
+ If work is enqueued by a <span class="emphasis"><em>worker-thread</em></span> the <span class="underline">_action</span>_ is stored in the worker queue. If
+ the work is enqueued by a application thread it goes into the global queue.
+ When <span class="emphasis"><em>worker-threads</em></span> are looking for work, they have
+ following search order:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ look into the private worker-queue - <span class="underline">_tasks</span>_
+ can be dequeued without locks
+ </li>
+<li class="listitem">
+ look in the global-queue - locks are used for synchronization
+ </li>
+<li class="listitem">
+ check other worker-queues ('stealing' <span class="underline">_tasks</span>_
+ from private worker queues of other <span class="emphasis"><em>worker-threads</em></span>)
+ - requires locks
+ </li>
+</ul></div>
+<p>
+ For a lot of recursively queued <span class="underline">_tasks</span>_
+ (so called <span class="emphasis"><em>sub-tasks</em></span>), the use of a worker-queue per
+ thread substantially reduces the synchronization necessary to complete
+ the work. There are also fewer cache effects due to sharing of the global-queue
+ information.
+ </p>
+<p>
+ Operations on the private worker queue are executed in LIFO order and operations
+ on worker queues of other <span class="emphasis"><em>worker-threads</em></span> in FIFO order
+ (steals).
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ There are chances that memory is still hot in the cache, if the <span class="underline">_tasks</span>_ are pushed in LIFO order into the
+ private worker queue.
+ </li>
+<li class="listitem">
+ If a <span class="emphasis"><em>worker-thread</em></span> 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 <span class="emphasis"><em>sub-tasks</em></span>
+ are stored in LIFO order, the oldest items are closer to the <span class="emphasis"><em>public
+ end</em></span> of the queue (forming a tree). Stealing such an older
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> also steals a (probably) larger
+ subtree of <span class="underline">_tasks</span>_ unfolded if
+ the stolen work item get executed. Since a <span class="emphasis"><em>sub-task</em></span>
+ is just part of a larger <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>,
+ we don&#8217;t need to worry about execution order.
+ </li>
+</ul></div>
+</div>
+<p>
+ / 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
+ ]
+ </p>
+<div class="section" title="Fork/Join">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_task.async_executor.pool.forkjoin"></a><a class="link" href="async_executor.html#boost_task.async_executor.pool.forkjoin" title="Fork/Join"> Fork/Join</a>
+</h4></div></div></div>
+<p>
+ Fork/Join algorithms are recursive divide-and-conquer algorithms which
+ repeatedly splitt __sub<span class="underline">taskss</span>_ until
+ they become small enough to solve using simple, short sequential methods,
+ so that they run in parallel on multiple cores.
+ </p>
+<p>
+ The fork operation creates new <span class="emphasis"><em>sub-tasks</em></span> which can
+ run in parallel. The current <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ is not proceeded in the join operation until the forked <span class="emphasis"><em>sub-tasks</em></span>
+ have completed. In the meantime the <span class="emphasis"><em>worker-thread</em></span>
+ executes other <span class="underline">_tasks</span>_ from its local
+ worker-queue.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">&lt;</span> <span class="number">2</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">n</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="keyword">return</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">);</span>
+<span class="special">}</span>
+
+<span class="keyword">long</span> <span class="identifier">parallel_fib</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">long</span> <span class="identifier">cutof</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">&lt;</span> <span class="identifier">cutof</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span>
+ <span class="special">{</span>
+ <span class="comment">// fork a sub-task calculating fibonacci(n-1)
+</span> <span class="identifier">h1</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">parallel_fib</span><span class="special">,</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span>
+ <span class="identifier">cutof</span><span class="special">)</span> <span class="special">);</span>
+ <span class="comment">// fork a sub-task calculating fibonacci(n-2)
+</span> <span class="identifier">h2</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">parallel_fib</span><span class="special">,</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">,</span>
+ <span class="identifier">cutof</span><span class="special">)</span> <span class="special">);</span>
+ <span class="comment">// join the results of both sub-tasks
+</span> <span class="comment">// if one of the both sub-tasks is not ready
+</span> <span class="comment">// the worker-thread does not block, it executes other
+</span> <span class="comment">// task from its local-queue
+</span> <span class="keyword">return</span> <span class="identifier">h1</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">h2</span><span class="special">.</span><span class="identifier">get</span><span class="special">();</span>
+ <span class="special">}</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// handle for fibonacci calculation
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">(),</span> <span class="comment">// access the default thread-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// calculate fibonacci number 10
+</span> <span class="identifier">parallel_fib</span><span class="special">,</span> <span class="comment">// for numbers &lt; 5 do inline recursive calculation
+</span> <span class="number">10</span><span class="special">,</span>
+ <span class="number">5</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+</div>
+<div class="section" title="boost::task::as_sub_task">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.async_executor.as_sub_task"></a><a class="link" href="async_executor.html#boost_task.async_executor.as_sub_task" title="boost::task::as_sub_task"> <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span></code></a>
+</h3></div></div></div>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span></code> is a convenient way to execute
+ a <span class="emphasis"><em>sub-task</em></span>. If the parent task is executed inside a
+ <span class="emphasis"><em>thread-pool</em></span> the <span class="emphasis"><em>sub-task</em></span> is put
+ into the local-queue of the <span class="emphasis"><em>worker-thread</em></span> in the other
+ case the <span class="emphasis"><em>sub-task</em></span> will be executed in a new thread.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">fibonacci</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+<p>
+ is equivalent to:
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">if</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">runs_in_pool</span><span class="special">()</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="comment">// put the sub-task into worker-threads local-queue
+</span><span class="special">}</span>
+<span class="keyword">else</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(...)</span> <span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a name="ftn.id665925" href="#id665925" class="para">4</a>] </sup>
+ see <a href="http://www.ddj.com/go-parallel/article/showArticle.jhtml?articleID=216500409" target="_top">'Use
+ Thread Pools Correctly'</a>, Herb Sutter
+ </p></div>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="handle.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="utilities.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/callable.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/callable.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,321 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Callable</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="motivation.html" title="Motivation">
+<link rel="next" href="async_completion_token.html" title="Asynchronous completion token">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="motivation.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="async_completion_token.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Callable">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.callable"></a><a class="link" href="callable.html" title="Callable"> Callable</a>
+</h2></div></div></div>
+<div class="toc"><dl><dt><span class="section"> Task</span></dt></dl></div>
+<p>
+ The <span class="emphasis"><em>callable</em></span> encapsulates the function object and provides
+ for this purpose <code class="computeroutput"><span class="keyword">operator</span><span class="special">()()</span></code>.
+ </p>
+<div class="section" title="Task">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.callable.task"></a><a class="link" href="callable.html#boost_task.callable.task" title="Task"> Task</a>
+</h3></div></div></div>
+<p>
+ A task is a chunk of code that can be executed independently.
+ </p>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> represents a <span class="emphasis"><em>callable</em></span>
+ (provides <code class="computeroutput"><span class="keyword">operator</span><span class="special">()()</span></code>)
+ object containing the unit of code to be execute by a link<span class="underline">ae[</span><span class="underline">ae</span>_]. Function <code class="computeroutput"><span class="identifier">get_future</span><span class="special">()</span></code> returns a link<span class="underline">act[</span><span class="underline">act</span>_] allowing to wait for the completion of
+ the computation of the task, for getting the result of a computation or for
+ transfering exceptions. Each <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ has a unique identifier
+ </p>
+<a name="boost_task.callable.task.creation"></a><h5>
+<a name="id635193"></a>
+ <a class="link" href="callable.html#boost_task.callable.task.creation">Creation</a>
+ </h5>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">()</span></code>
+ can be used to create <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ by passing free-functions or member-functions of objects and its arguments:
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">()</span></code>
+ accepts up to ten arguments per default (can be overriden by defining BOOST_TASK_MAKE_TASK_MAX_ARITY
+ with the new value).
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
+ create task from free-function with arguments:
+ </li></ul></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="identifier">t</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">parallel_fib</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
+ create task from member-function with arguments:
+ </li></ul></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span>
+<span class="special">{</span>
+ <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">);</span>
+<span class="special">};</span>
+
+<span class="identifier">X</span> <span class="identifier">x</span><span class="special">;</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="identifier">t</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="special">&amp;</span> <span class="identifier">X</span><span class="special">::</span><span class="identifier">f</span><span class="special">,</span>
+ <span class="identifier">x</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+<p>
+ It is possible to create <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ from a <span class="emphasis"><em>callable</em></span> too:
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">Y</span>
+<span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">operator</span><span class="special">()();</span>
+<span class="special">};</span>
+
+<span class="identifier">Y</span> <span class="identifier">y</span><span class="special">;</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&gt;</span> <span class="identifier">t</span><span class="special">(</span> <span class="identifier">y</span><span class="special">);</span>
+</pre>
+<p>
+ </p>
+<a name="boost_task.callable.task.cooperative_task_amd_interruption"></a><h5>
+<a name="id635764"></a>
+ <a class="link" href="callable.html#boost_task.callable.task.cooperative_task_amd_interruption">Cooperative
+ task amd interruption</a>
+ </h5>
+<p>
+ Sometimes it is desired to stop a running task if it is no longer needed.
+ In this case the thread is not killed - it stops only at well-defined points
+ (<span class="underline">_interruption</span><span class="underline">points</span>_)
+ its execution. In the context of task-interruption a task is known as cooperative
+ if it checks for an interruption request between two <span class="underline">_interruption</span><span class="underline">points</span>_ via <span class="underline">_fn</span>_interruption<span class="underline">requested</span>_
+ <sup>[<a name="id635810" href="#ftn.id635810" class="footnote">2</a>]</sup>
+ .
+ </p>
+<p>
+ <span class="underline">_interruption</span><span class="underline">points</span>_
+ are:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">join</span><span class="special">()</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">timed_join</span><span class="special">()</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable</span><span class="special">::</span><span class="identifier">wait</span><span class="special">()</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable</span><span class="special">::</span><span class="identifier">timed_wait</span><span class="special">()</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable_any</span><span class="special">::</span><span class="identifier">wait</span><span class="special">()</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable_any</span><span class="special">::</span><span class="identifier">timed_wait</span><span class="special">()</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span><span class="special">::</span><span class="identifier">sleep</span><span class="special">()</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep</span><span class="special">()</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">()</span></code></li>
+</ul></div>
+<p>
+ A <span class="underline">_interruption</span><span class="underline">point</span>_
+ throws <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task_interrupted</span></code> if an interruption was
+ requested.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">cooperative</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_requested</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// check if interruption was requested
+</span> <span class="keyword">return</span><span class="special">;</span>
+
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// get handle associated with the task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// task, to be executed asynchronously
+</span> <span class="identifier">cooperative</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// throws boost::task::task_interrupted
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+<a name="boost_task.callable.task.exceptions"></a><h5>
+<a name="id636888"></a>
+ <a class="link" href="callable.html#boost_task.callable.task.exceptions">Exceptions</a>
+ </h5>
+<p>
+ Exceptions thrown by <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ are transported by the <span class="emphasis"><em>asynchronous-completion-token</em></span>.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">throwing</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="special">...</span>
+ <span class="keyword">throw</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">domain_error</span><span class="special">(</span><span class="string">"domain error"</span><span class="special">);</span>
+ <span class="special">...</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">void</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// get handle associated with the task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// task, to be executed asynchronously
+</span> <span class="identifier">throwing</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">wait</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// throws std::domain_error
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ Exceptions rethrown by type are:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_alloc</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_cast</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_exception</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_typeid</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">domain_error</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">invalid_argument</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">failure</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">length_error</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">logic_error</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">out_of_range</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">range_error</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">underflow_error</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">future_already_set</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">future_cancel</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">exception</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">invalid_thread_argument</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">lock_error</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task_interrupted</span></code></li>
+<li class="listitem"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">broken_task</span></code></li>
+</ul></div>
+<a name="boost_task.callable.task.parent_task"></a><h5>
+<a name="id637692"></a>
+ <a class="link" href="callable.html#boost_task.callable.task.parent_task">Parent-task</a>
+ </h5>
+<p>
+ Top-level tasks have no parent. A parent task can create child tasks when
+ it creates another task by using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span></code>
+ as <span class="emphasis"><em>asynchronous-executor</em></span>. These children are implicitly
+ treated as <span class="emphasis"><em>sub-tasks</em></span> of the larger task. It is assumed
+ that that <span class="emphasis"><em>sub-tasks</em></span> can be executed in any order because
+ only overall operation speed matters (enabling strategies for fast execution
+ of unordered <span class="emphasis"><em>work-items</em></span> as <a class="link" href="../"><span class="emphasis"><em>work-stealing</em></span></a>).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">&lt;</span> <span class="number">2</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">n</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="keyword">return</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">);</span>
+<span class="special">}</span>
+
+<span class="keyword">long</span> <span class="identifier">parallel_fib</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">long</span> <span class="identifier">cutof</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">&lt;</span> <span class="identifier">cutof</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span>
+ <span class="special">{</span>
+ <span class="comment">// submit a sub-task to pool calculating fibonacci(n-1)
+</span> <span class="identifier">h1</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span><span class="special">(),</span> <span class="comment">// execute a sub-task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">parallel_fib</span><span class="special">,</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span>
+ <span class="identifier">cutof</span><span class="special">)</span> <span class="special">);</span>
+ <span class="comment">// submit a sub-task to pool calculating fibonacci(n-2)
+</span> <span class="identifier">h2</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span><span class="special">(),</span> <span class="comment">// execute a sub-task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">parallel_fib</span><span class="special">,</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">,</span>
+ <span class="identifier">cutof</span><span class="special">)</span> <span class="special">);</span>
+ <span class="comment">// calculate fibonacci(n) from the results of both sub-tasks
+</span> <span class="keyword">return</span> <span class="identifier">h1</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">h2</span><span class="special">.</span><span class="identifier">get</span><span class="special">();</span>
+ <span class="special">}</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// handle for fibonacci calculation
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">(),</span> <span class="comment">// access the default thread-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// calculate fibonacci number 10
+</span> <span class="identifier">parallel_fib</span><span class="special">,</span> <span class="comment">// for numbers &lt; 5 do inline recursive calculation
+</span> <span class="number">10</span><span class="special">,</span>
+ <span class="number">5</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a name="ftn.id635810" href="#id635810" class="para">2</a>] </sup>
+ see 'Interrupt Politely',
+ Herb Sutter
+ </p></div>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="motivation.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="async_completion_token.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/description.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/description.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,41 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Description</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="motivation.html" title="Motivation">
+<link rel="next" href="task.html" title="Task">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="motivation.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Description"><div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.description"></a><a class="link" href="description.html" title="Description"> Description</a>
+</h2></div></div></div></div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="motivation.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/handle.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/handle.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,222 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Handle</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="task.html" title="Task">
+<link rel="next" href="own_thread.html" title="Execute in own thread">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="task.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="own_thread.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Handle">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.handle"></a><a class="link" href="handle.html" title="Handle"> Handle</a>
+</h2></div></div></div>
+<p>
+ The <span class="emphasis"><em>asynchronous-completion-token</em></span> dispatches tasks in
+ response to the completion of asynchronous operations. <span class="emphasis"><em>asynchronous-completion-token</em></span>
+ uniquely identifies the task and state necessary to process the result of the
+ operation
+ <sup>[<a name="id569908" href="#ftn.id569908" class="footnote">3</a>]</sup>
+ .
+ </p>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span></code>
+ represents an <span class="emphasis"><em>asynchronous-completion-token</em></span>. It will be
+ returned by <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code> and is associated with the submitted <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>.
+ </p>
+<a name="boost_task.handle.asynchronous_completion_token_interface"></a><h4>
+<a name="id570012"></a>
+ <a class="link" href="handle.html#boost_task.handle.asynchronous_completion_token_interface">Asynchronous
+ completion token interface</a>
+ </h4>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span></code>
+ implements an interface in order to check the state of computation and result
+ transfer
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">get_id</span><span class="special">()</span></code>:
+ return id of the associated task-id
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">is_ready</span><span class="special">()</span></code>:
+ test if result is set
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">has_value</span><span class="special">()</span></code>:
+ test if value-result is set
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">has_exception</span><span class="special">()</span></code>:
+ test if exception-result is set
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">get</span><span class="special">()</span></code>:
+ return value-result
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">wait</span><span class="special">()</span></code>:
+ wait until result is set
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">wait_for</span><span class="special">()</span></code>:
+ wait until result is set or time-duration has elapsed
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">wait_until</span><span class="special">()</span></code>:
+ wait until result ist set or time-point has elapsed
+ </li>
+</ul></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_requested</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// check if interruption was requested
+</span> <span class="keyword">return</span><span class="special">;</span>
+
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">fibonacci</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"id == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"is ready == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">is_ready</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">h</span><span class="special">.</span><span class="identifier">wait</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"has value == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">has_value</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"has exception == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">has_exception</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<a name="boost_task.handle.task_interruption"></a><h4>
+<a name="id571214"></a>
+ <a class="link" href="handle.html#boost_task.handle.task_interruption">Task interruption</a>
+ </h4>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">interrupt</span><span class="special">()</span></code>:
+ interrupt <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> and return immediately
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">interrupt_and_wait</span><span class="special">()</span></code>:
+ interrupt and wait until <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ was removed from <span class="emphasis"><em>worker-thread</em></span>
+</li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">interrupt_and_wait_for</span><span class="special">()</span></code>:
+ interrupt and wait until <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ was removed from <span class="emphasis"><em>worker-thread</em></span> or time duration has
+ elapsed
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">interrupt_and_wait_until</span><span class="special">()</span></code>: interrupt and wait until <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> was removed from <span class="emphasis"><em>worker-thread</em></span>
+ or time point has elapsed
+ </li>
+<li class="listitem">
+<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_requested</span><span class="special">()</span></code>:
+ return bool if interruption was requested
+ </li>
+</ul></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">cooperative</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_requested</span><span class="special">()</span> <span class="special">)</span> <span class="comment">// check if interruption was requested
+</span> <span class="keyword">return</span><span class="special">;</span>
+
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">interruption_point</span><span class="special">();</span> <span class="comment">// interruption point
+</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// get handle associated with the task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// task, to be executed asynchronously
+</span> <span class="identifier">cooperative</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">h</span><span class="special">.</span><span class="identifier">interrupt_and_wait</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"id == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get_id</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"is ready == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">is_ready</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"has value == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">has_value</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"has exception == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">has_exception</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// throws boost::task::task_interrupted
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a name="ftn.id569908" href="#id569908" class="para">3</a>] </sup>
+ see <a href="http://www.cs.wustl.edu/~schmidt/PDF/ACT.pdf" target="_top">'Asynchronous
+ Completion Token'</a>, Douglas Schmidt
+ </p></div>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="task.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="own_thread.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/meta_functions.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/meta_functions.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,63 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Meta functions</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="utilities.html" title="Utilities">
+<link rel="next" href="reference.html" title="Reference">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="utilities.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Meta functions">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.meta_functions"></a><a class="link" href="meta_functions.html" title="Meta functions"> Meta functions</a>
+</h2></div></div></div>
+<p>
+ If the <span class="emphasis"><em>thread-pool</em></span> supports attributes (like priorities)
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">has_attribute</span></code>
+ evaluates to <code class="computeroutput"><span class="keyword">true</span></code> at compile-time
+ (derived from boost::mpl::bool_). The type of the attribute is determined by
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">attribute_type</span></code>.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">typdef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">priority</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="comment">// pool with priority scheduling; integer as priority type
+</span><span class="special">&gt;</span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">boolalpha</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">has_attribute</span><span class="special">&lt;</span> <span class="identifier">pool_type</span> <span class="special">&gt;::</span><span class="identifier">value</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="keyword">typeid</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">attribute_type</span><span class="special">&lt;</span> <span class="identifier">pool_type</span> <span class="special">&gt;::</span><span class="identifier">type</span><span class="special">).</span><span class="identifier">name</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+</pre>
+<p>
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="utilities.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="reference.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/motivation.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/motivation.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,223 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Motivation</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="next" href="task.html" title="Task">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="../index.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Motivation">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.motivation"></a><a class="link" href="motivation.html" title="Motivation"> Motivation</a>
+</h2></div></div></div>
+<p>
+ To speed-up computer-bound work and/or increase the computation-throughput
+ is a common motivation for parallelizing a program. Especially for interactive
+ applications that have to process user input while performing some background
+ tasks responsivness iss very important. Parallelizing a program requires partitioning
+ the program into smaller chunks that can run in parallel. The code can scale
+ as the hardware gets better without changing the code.
+ </p>
+<p>
+ The evolution from one-core to many-core architectures and the usage of threads
+ (of course processes fit too) support this paradigm.
+ </p>
+<div class="note" title="Note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ <span class="quote">&#8220;<span class="quote">You can have multithreading on a single core machine, but you can
+ only have parallelism on a multi core machine ... .</span>&#8221;</span> -- Daniel Moth
+ <sup>[<a name="id563974" href="#ftn.id563974" class="footnote">1</a>]</sup>
+ </p></td></tr>
+</table></div>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> provides a framework to utilize
+ the available hardware and provide a way for efficient asynchronous processing
+ of time consuming operations. The framework provides some <span class="emphasis"><em>asynchronous-executors</em></span>,
+ like <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span></code>,
+ in order to execute the task asynchronously in another execution context (<span class="bold"><strong>Boost.Task</strong></span> uses preemptible threads for this purpose).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">print</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">msg</span><span class="special">)</span>
+<span class="special">{</span> <span class="identifier">printf</span><span class="special">(</span><span class="string">"%s\n"</span><span class="special">,</span> <span class="identifier">msg</span><span class="special">.</span><span class="identifier">c_str</span><span class="special">()</span> <span class="special">);</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span> <span class="comment">// dispatchs task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// task, to be executed asynchronously
+</span> <span class="identifier">print</span><span class="special">,</span>
+ <span class="string">"Hello World!"</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ In order to manage the task <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code> returns
+ a handle <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span></code>
+ (associated with the submitted task). It functions as a <span class="emphasis"><em>asynchronous-completion-token</em></span>
+ - that means it transfers the result of the execution back to the caller thread.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">echo</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">msg</span><span class="special">)</span>
+<span class="special">{</span> <span class="keyword">return</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// get handle associated with the task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// task, to be executed asynchronously
+</span> <span class="identifier">echo</span><span class="special">,</span>
+ <span class="string">"Hello World!"</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// wait until task is finished and return the result
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ The task can also be interrupted via <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span></code> if it is a so-called <a class="link" href="task.html" title="Task"><span class="emphasis"><em>cooperative
+ task</em></span></a>.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">long_running</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">time_duration</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rel_time</span><span class="special">)</span>
+<span class="special">{</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep</span><span class="special">(</span> <span class="identifier">rel_time</span><span class="special">);</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// get handle associated with the task
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// long runing task, to be executed asynchronously
+</span> <span class="identifier">long_running</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">millisec</span><span class="special">(</span> <span class="number">500</span><span class="special">)</span> <span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">h</span><span class="special">.</span><span class="identifier">interrupt</span><span class="special">();</span> <span class="comment">// interrupt execution of task
+</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// wait until task is finished, will throw an exeception
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ Beside <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span></code>
+ (which creates a new task for each submitted task) <span class="bold"><strong>Boost.Task</strong></span>
+ provides <a class="link" href="pool.html" title="Thread-pool"><span class="emphasis"><em>thread-pools</em></span></a>
+ to prevent the overhead of thread creation and destruction for each task.
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span></code>
+ submitts the tasks to the default <span class="emphasis"><em>thread-pool</em></span> which contains
+ a fixed number of pre-spawned <span class="emphasis"><em>worker-threads</em></span> (custom
+ <span class="emphasis"><em>thread-pools</em></span> are supported too).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">&lt;</span> <span class="number">2</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">n</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="keyword">return</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">);</span>
+<span class="special">}</span>
+
+<span class="keyword">long</span> <span class="identifier">parallel_fib</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">long</span> <span class="identifier">cutof</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">&lt;</span> <span class="identifier">cutof</span><span class="special">)</span> <span class="keyword">return</span> <span class="identifier">serial_fib</span><span class="special">(</span> <span class="identifier">n</span><span class="special">);</span>
+ <span class="keyword">else</span>
+ <span class="special">{</span>
+ <span class="comment">// fork a sub-task calculating fibonacci(n-1)
+</span> <span class="identifier">h1</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_pool</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">parallel_fib</span><span class="special">,</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span>
+ <span class="identifier">cutof</span><span class="special">)</span> <span class="special">);</span>
+ <span class="comment">// fork a sub-task calculating fibonacci(n-2)
+</span> <span class="identifier">h2</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">get_pool</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">parallel_fib</span><span class="special">,</span>
+ <span class="identifier">n</span> <span class="special">-</span> <span class="number">2</span><span class="special">,</span>
+ <span class="identifier">cutof</span><span class="special">)</span> <span class="special">);</span>
+ <span class="comment">// join the results of both sub-tasks
+</span> <span class="keyword">return</span> <span class="identifier">h1</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">h2</span><span class="special">.</span><span class="identifier">get</span><span class="special">();</span>
+ <span class="special">}</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span> <span class="comment">// handle for fibonacci calculation
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">(),</span> <span class="comment">// access the default thread-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// calculate fibonacci number 10
+</span> <span class="identifier">parallel_fib</span><span class="special">,</span> <span class="comment">// for numbers &lt; 5 do inline recursive calculation
+</span> <span class="number">10</span><span class="special">,</span>
+ <span class="number">5</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ With function <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">this_task</span><span class="special">::</span><span class="identifier">runs_in_pool</span><span class="special">()</span></code>
+ a task can detect if it is executed inside a <span class="emphasis"><em>thread-pool</em></span>.
+ <span class="emphasis"><em>sub-tasks</em></span> arecreated by <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span></code>. Where the <span class="emphasis"><em>sub-task</em></span>
+ is executed by a new thread if the parent task is not executed inside a <span class="emphasis"><em>thread-pool</em></span>.
+ In the other case the <span class="emphasis"><em>sub-task</em></span> is put into the local
+ <span class="emphasis"><em>worker-queue</em></span> which enables <a class="link" href="pool.html#boost_task.pool.work_stealing" title="Work-Stealing"><span class="emphasis"><em>work-stealing</em></span></a>
+ and <a class="link" href="pool.html#boost_task.pool.forkjoin" title="Fork/Join">inline execution</a> of tasks.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">as_sub_task</span><span class="special">(),</span> <span class="comment">// sub-task executed in a new thread or inside
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="comment">// the thread-pool depending upon the parent
+</span> <span class="identifier">parallel_fib</span><span class="special">,</span> <span class="comment">// task is executed inside a thread-pool or not
+</span> <span class="number">10</span><span class="special">,</span>
+ <span class="number">5</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a name="ftn.id563974" href="#id563974" class="para">1</a>] </sup>
+ more to read at Daniel's blog
+ </p></div>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="../index.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/new_thread.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/new_thread.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,109 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Execute in new thread</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="own_thread.html" title="Execute in own thread">
+<link rel="next" href="pool.html" title="Thread-pool">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="own_thread.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="pool.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Execute in new thread">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.new_thread"></a><a class="link" href="new_thread.html" title="Execute in new thread"> Execute in new thread</a>
+</h2></div></div></div>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span></code>
+ creates a new <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">thread</span></code> and executes the task in this thread
+ (asynchronous). The created thread gets joined by handle (so N2802
+ should be addressed).
+ </p>
+<div class="caution" title="Caution"><table border="0" summary="Caution">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../doc/html/images/caution.png"></td>
+<th align="left">Caution</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Always store the returned <span class="emphasis"><em>asynchronous-completion-token</em></span>
+ in a variable because <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span></code>
+ joins the thread in its destructor (if the last reference gets out of scope).
+ </p></td></tr>
+</table></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">fibonacci</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ In the example below both <code class="computeroutput"><span class="identifier">a_function</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">another_function</span><span class="special">()</span></code> are executed synchron (see <a class="link" href="own_thread.html" title="Execute in own thread"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">own_thread</span></code></a>
+ for synchronous execution)!
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">a_function</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">new_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">another_function</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="own_thread.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="pool.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/own_thread.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/own_thread.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,79 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Execute in own thread</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="handle.html" title="Handle">
+<link rel="next" href="new_thread.html" title="Execute in new thread">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="handle.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="new_thread.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Execute in own thread">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.own_thread"></a><a class="link" href="own_thread.html" title="Execute in own thread"> Execute in own thread</a>
+</h2></div></div></div>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">own_thread</span></code>
+ executes the task in the current thread (synchronous execution - concerns of
+ N2802
+ do not aply).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">own_thread</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">fibonacci</span><span class="special">,</span>
+ <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="handle.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="new_thread.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/task/libs/task/doc/html/boost_task/pool.html
==============================================================================
--- (empty file)
+++ sandbox/task/libs/task/doc/html/boost_task/pool.html 2009-06-01 08:13:01 EDT (Mon, 01 Jun 2009)
@@ -0,0 +1,729 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Thread-pool</title>
+<link rel="stylesheet" href="../boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.75.0">
+<link rel="home" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="up" href="../index.html" title="Chapter 1. Boost.Task">
+<link rel="prev" href="new_thread.html" title="Execute in new thread">
+<link rel="next" href="as_sub_task.html" title="Execute as sub-task">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="new_thread.html"><img src="../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="as_sub_task.html"><img src="../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" title="Thread-pool">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_task.pool"></a><a class="link" href="pool.html" title="Thread-pool"> Thread-pool</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"> Static thread-pool</span></dt>
+<dt><span class="section"> Channel</span></dt>
+<dt><span class="section"> Scheduling</span></dt>
+<dt><span class="section"> Pool shutdown</span></dt>
+<dt><span class="section"> Default pool</span></dt>
+<dt><span class="section"> Processor binding</span></dt>
+<dt><span class="section"> Work-Stealing</span></dt>
+<dt><span class="section"> Fork/Join</span></dt>
+</dl></div>
+<p>
+ Instead of creating a new thread and quickly throwing it away after the task
+ is done, the overhead related to thread creation and destruction can be avoided
+ by running the <span class="emphasis"><em>work-items</em></span> on a <span class="emphasis"><em>thread-pool</em></span>
+ (reusing an existing <span class="emphasis"><em>worker-thread</em></span> instead).
+ </p>
+<p>
+ A <span class="emphasis"><em>thread-pool</em></span> maintains a queue (or queues) of <span class="emphasis"><em>work-items</em></span>
+ to be done, and a pool of <span class="emphasis"><em>worker-threads</em></span> which execute
+ <span class="emphasis"><em>work-items</em></span> from the queue(s).
+ </p>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> provides <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code> with
+ support of executing an <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> in <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span></code> (using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">()</span></code>):
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">echo</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">msg</span><span class="special">)</span>
+<span class="special">{</span> <span class="keyword">return</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">default_pool</span><span class="special">(),</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">echo</span><span class="special">,</span>
+ <span class="string">"Hello World!"</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ and a custom <span class="emphasis"><em>thread-pool</em></span> (passing pool instance as an
+ argument to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code>):
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">echo</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">msg</span><span class="special">)</span>
+<span class="special">{</span> <span class="keyword">return</span> <span class="identifier">msg</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">fifo</span>
+ <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">5</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">&gt;</span> <span class="identifier">h</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span>
+ <span class="identifier">echo</span><span class="special">,</span>
+ <span class="string">"Hello World!"</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">h</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ .
+ </p>
+<div class="important" title="Important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../doc/html/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Tasks should not be too small (performance overhead dominates) and avoid
+ blocking tasks
+ <sup>[<a name="id575100" href="#ftn.id575100" class="footnote">4</a>]</sup>
+ .
+ </p></td></tr>
+</table></div>
+<div class="section" title="Static thread-pool">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.pool.static_pool"></a><a class="link" href="pool.html#boost_task.pool.static_pool" title="Static thread-pool"> Static thread-pool</a>
+</h3></div></div></div>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> provides <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span></code>
+ - which contains an fixed set of pre-forked <span class="emphasis"><em>worker-threads</em></span>
+ (the size of the pool doesn't change during its lifetime).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">_static_pool</span><span class="special">&lt;</span> <span class="comment">// pool type
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span> <span class="comment">// queuing policy (unbounded_channel, bounded_channel)
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">fifo</span> <span class="comment">// scheduling policy (fifo, priority, smart)
+</span> <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">6</span><span class="special">),</span> <span class="comment">// pool with 6 pre-forked worker-threads
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">posix_time</span><span class="special">::</span><span class="identifier">milliseconds</span><span class="special">(</span> <span class="number">50</span><span class="special">),</span> <span class="comment">// time to sleep if no work-item available
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">scanns</span><span class="special">(</span> <span class="number">10</span><span class="special">)</span> <span class="special">);</span> <span class="comment">// iterations over local-queues before sleep
+</span></pre>
+<p>
+ </p>
+<p>
+ The first argument of the constructor specifies how many <span class="emphasis"><em>worker-threads</em></span>
+ the pool will contain. The second and third argument are used by the <a class="link" href="pool.html#boost_task.pool.work_stealing" title="Work-Stealing"><span class="emphasis"><em>work-stealing</em></span></a>
+ algorithm.
+ </p>
+<div class="note" title="Note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ If <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">bounded_channel</span></code> is used as queuing policy
+ the constructor has two additional arguments .
+ </p></td></tr>
+</table></div>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span></code> provides functionality to check
+ the status of the pool - <code class="computeroutput"><span class="identifier">close</span><span class="special">()</span></code> returns true when the pool was shutdown
+ and <code class="computeroutput"><span class="identifier">active</span><span class="special">()</span></code>
+ as well as <code class="computeroutput"><span class="identifier">idle</span><span class="special">()</span></code>
+ returning how many <span class="emphasis"><em>worker-threads</em></span> are active (executing
+ a task) or idle. The size of the pool can be accessed over <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code>.
+ </p>
+<p>
+ For infomational pruposes <code class="computeroutput"><span class="identifier">empty</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">pending</span><span class="special">()()</span></code> can be used in order to know if the global
+ task-queue is empty or how many tasks are waiting for execution. With <code class="computeroutput"><span class="identifier">clear</span><span class="special">()</span></code>
+ all tasks are removed from the global-queue.
+ </p>
+<div class="note" title="Note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ <code class="computeroutput"><span class="identifier">pending</span><span class="special">()()</span></code>
+ does not count tasks in the local-queues of the <span class="emphasis"><em>worker-threads</em></span>.
+ </p></td></tr>
+</table></div>
+</div>
+<div class="section" title="Channel">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.pool.channel"></a><a class="link" href="pool.html#boost_task.pool.channel" title="Channel"> Channel</a>
+</h3></div></div></div>
+<p>
+ The channel synchronizes the access between non-pool threads (application
+ threads) and <span class="emphasis"><em>worker-threads</em></span> and implements a queuing
+ policy (limitation of queued tasks).
+ </p>
+<a name="boost_task.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__bounded_channel__phrase___code_"></a><h5>
+<a name="id575703"></a>
+ <a class="link" href="pool.html#boost_task.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__bounded_channel__phrase___code_"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">bounded_channel</span></code></a>
+ </h5>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">bounded_channel</span></code> contains a single lock
+ in order to synchronize access to the queue. The number of pending tasks
+ is limited in order to prevent resource exhaustion. For this purpose a high-
+ and low-watermark has to be passed at construction. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">high_watermark</span></code>
+ sets the maximum of pending tasks. If this limited is reached all threads
+ which submit a task will be set to sleep (blocked). If it is equal to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">low_watermark</span></code> everytime a sleeping producer
+ thread will be woken up and puts its task if one worker thread has taken
+ a task from the channel. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">low_watermark</span></code>
+ sets the threshold when blocked threads get woken up. If it is less than
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">high_watermark</span></code> all sleeping producer threads
+ will be woken up if the amount of pending tasks reaches <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">low_watermark</span></code>.
+ </p>
+<a name="boost_task.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__unbounded_channel__phrase___code_"></a><h5>
+<a name="id575935"></a>
+ <a class="link" href="pool.html#boost_task.pool.channel._code__phrase_role__identifier__boost__phrase__phrase_role__special______phrase__phrase_role__identifier__task__phrase__phrase_role__special______phrase__phrase_role__identifier__unbounded_channel__phrase___code_"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span></code></a>
+ </h5>
+<p>
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span></code> contains a single lock
+ in order to synchronize access to the queue. An unlimited number of tasks
+ can be queued into this channel. The insertion of an <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ will never block. If the channel becomes empty <span class="emphasis"><em>worker-threads</em></span>
+ will be set to sleep until new tasks are enqueued.
+ </p>
+</div>
+<div class="section" title="Scheduling">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.pool.scheduling"></a><a class="link" href="pool.html#boost_task.pool.scheduling" title="Scheduling"> Scheduling</a>
+</h3></div></div></div>
+<p>
+ The scheduling policy determines how tasks are scheduled inside the <span class="emphasis"><em>channel</em></span>.
+ </p>
+<a name="boost_task.pool.scheduling.fifo"></a><h5>
+<a name="id576076"></a>
+ <a class="link" href="pool.html#boost_task.pool.scheduling.fifo">fifo</a>
+ </h5>
+<p>
+ First inserted pending <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code>
+ gets taken first.
+ </p>
+<a name="boost_task.pool.scheduling.priority"></a><h5>
+<a name="id576127"></a>
+ <a class="link" href="pool.html#boost_task.pool.scheduling.priority">priority</a>
+ </h5>
+<p>
+ Each <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> is submitted to the pool with a priority
+ attribute. The type and ordering of the priority is user-defined.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span> <span class="comment">// allow unlimited tasks to be queue in global-queue
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">priority</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="comment">// tasks with lower priority are scheduled first
+</span><span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">5</span><span class="special">)</span> <span class="special">);</span>
+
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// thread-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">some_fn</span><span class="special">),</span> <span class="comment">// task to be executed
+</span> <span class="number">5</span><span class="special">);</span> <span class="comment">// priority is 5
+</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// thread-pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">another_fn</span><span class="special">),</span> <span class="comment">// task to be executed
+</span> <span class="number">3</span><span class="special">);</span> <span class="comment">// priority is 3
+</span></pre>
+<p>
+ </p>
+<p>
+ In this example the tasks get scheduled by the assigned integer (third argument
+ of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">()</span></code>).
+ The <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> with the lowest priority gets scheduled
+ first (taken by a <span class="emphasis"><em>worker-thread</em></span>). The ordering can be
+ changed by the second argument of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">priority</span></code>
+ (the default is <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span> <span class="identifier">Attr</span> <span class="special">&gt;</span></code>).
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">priority</span><span class="special">&lt;</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">greater</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;</span> <span class="comment">// tasks with higher priority are scheduled first
+</span>
+<span class="special">&gt;</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">5</span><span class="special">)</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+<a name="boost_task.pool.scheduling.smart"></a><h5>
+<a name="id576914"></a>
+ <a class="link" href="pool.html#boost_task.pool.scheduling.smart">smart</a>
+ </h5>
+<p>
+ Each inserted <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">task</span></code> is associated with an attribute. The
+ scheduler gets an put- and take-policy as template arguments. The corresponding
+ policy gets applied for each insertion and removal.
+ </p>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> provides <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">replace_oldest</span></code>
+ as put- policy and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">take_oldest</span></code>
+ as take-policy. Both policies allow the replacement of older (pending) tasks
+ in the scheduler by new ones.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci_fn</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">smart</span><span class="special">&lt;</span>
+ <span class="keyword">int</span><span class="special">,</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">&gt;,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">replace_oldest</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">take_oldest</span>
+ <span class="special">&gt;</span>
+ <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">1</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="special">...</span>
+
+ <span class="comment">// replaced by later task with same attribute == 2
+</span> <span class="comment">// if still pending in pool
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">10</span><span class="special">),</span>
+ <span class="number">2</span><span class="special">);</span> <span class="comment">// attribute is 2
+</span>
+ <span class="comment">// will replace previous pending task with attribute == 2
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">5</span><span class="special">),</span>
+ <span class="number">2</span><span class="special">);</span> <span class="comment">// attribute is 2 too
+</span><span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section" title="Pool shutdown">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_task.pool.pool_shutdown"></a><a class="link" href="pool.html#boost_task.pool.pool_shutdown" title="Pool shutdown"> Pool shutdown</a>
+</h3></div></div></div>
+<p>
+ <span class="bold"><strong>Boost.Task</strong></span> allows to shutdown a <span class="emphasis"><em>thread-pool</em></span>
+ explicitly via functions <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">shutdown_now</span><span class="special">()</span></code>. The destructor of the pool calls <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code>
+ if not already done so that all <span class="emphasis"><em>worker-threads</em></span> are joined
+ and the topic of N2802
+ should be addressed.
+ </p>
+<a name="boost_task.pool.pool_shutdown.shutdown"></a><h5>
+<a name="id578010"></a>
+ <a class="link" href="pool.html#boost_task.pool.pool_shutdown.shutdown">Shutdown</a>
+ </h5>
+<p>
+ If <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code>
+ is called - the the pool is set the closed state and all <span class="emphasis"><em>worker-threads</em></span>
+ are joined until all pending tasks are processed. No futher tasks can be
+ submitted.
+ </p>
+<div class="note" title="Note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ The deconstructor calls <code class="computeroutput"><span class="identifier">shutdown</span><span class="special">()</span></code> if the pool was not shutdown yet.
+ </p></td></tr>
+</table></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci_fn</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">0</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">k1</span><span class="special">(</span> <span class="number">1</span><span class="special">),</span> <span class="identifier">k2</span><span class="special">(</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">(</span> <span class="number">2</span><span class="special">);</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">tmp</span><span class="special">(</span> <span class="identifier">k1</span><span class="special">);</span>
+ <span class="identifier">k1</span> <span class="special">=</span> <span class="identifier">k1</span> <span class="special">+</span> <span class="identifier">k2</span><span class="special">;</span>
+ <span class="identifier">k2</span> <span class="special">=</span> <span class="identifier">tmp</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="identifier">k1</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">static_pool</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">unbounded_channel</span><span class="special">&lt;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">fifo</span>
+ <span class="special">&gt;</span>
+<span class="special">&gt;</span> <span class="identifier">pool_type</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">pool_type</span> <span class="identifier">pool</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">poolsize</span><span class="special">(</span> <span class="number">1</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="special">...</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h1</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">10</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">handle</span><span class="special">&lt;</span> <span class="keyword">long</span> <span class="special">&gt;</span> <span class="identifier">h2</span><span class="special">(</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">async</span><span class="special">(</span>
+ <span class="identifier">pool</span><span class="special">,</span> <span class="comment">// asynchronous executor
+</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">task</span><span class="special">::</span><span class="identifier">make_task</span><span class="special">(</span> <span class="identifier">fibonacci_fn</span><span class="special">,</span> <span class="number">5</span><span class="special">)</span> <span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">pool</span><span class="special">.</span><span class="identifier">shutdown</span><span class="special">();</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(10) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h1</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"fibonacci(5) == "</span> <span class="special">&lt;&lt;</span> <span class="identifier">h2</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<a name="boost_task.pool.pool_shutdown.shutdown_immediatly"></a><h5>
+<a name="id579109"></a>
+ <a class="link" href="pool.html#boost_task.pool.pool_shutdown.shutdown_immediatly">Shutdown
+ immediatly</a>
+ </h5>
+<p>
+ The function <code class="computeroutput"><span class="identifier">shutdown_now</span><span class="special">()</span></code> closes the pool, interrupts and then joins
+ all <span class="emphasis"><em>worker-threads</em></span>. Pending tasks are unprocessed.
+ </p>
+<p>
+
+</p>
+<pre class="programlisting"><span class="keyword">long</span> <span class="identifier">fibonacci_fn</span><span class="special">(</span> <span class="keyword">long</span> <span class="identifier">n</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">n</span> <span class="special">==</span&