| 23 | |
| 24 | --------------------------------------------------------------------------------------------------- |
| 25 | == !AsynchronousExecutors == |
| 26 | * '''Author(s):''' Vicente J. Botet Escriba |
| 27 | * '''Version:''' 0.2 |
| 28 | * '''State:''' Preliminary |
| 29 | * '''Last upload:''' 2009 Jan 14 |
| 30 | * '''Links:''' [http://www.boostpro.com/vault/index.php?action=downloadfile&filename=interthreads.zip&directory=Concurrent%20Programming& Boost Vault] [https://svn.boost.org/svn/boost/sandbox/interthreads Boost Sandbox] |
| 31 | * '''Description:''' Asynchronous Executors (AE) and Asynchronous Completion Tokens (ACT) in a generic way (or at least this was my intention). The library can be considered as a front-end for several Asynchronous Execution models making it possible to share common algorithms and making easier to switch from an Asynchronous Executors to another. |
| 32 | |
| 33 | Next follows the motivation for the library and how the library can manage with this concepts. |
| 34 | |
| 35 | In N1833 - Preliminary Threading Library Proposal for TR2 Kevlin Henney introduce the concept of threader and a function thread that evaluate a function asynchronously and returns a joiner handle. |
| 36 | In N2185 - Proposed Text for Parallel Task Execution Peter Dimov introduce a fork function able to evaluate a function asynchronously and returns a future handle. |
| 37 | In N2276 - Thread Pools and Futures Anthony William introduce launch_in_thread and launch_in_pool function templates which evaluate a function asynchronously either in a specific thread or a thread pool and returns a unique_future handle. |
| 38 | In Boost.ThreadPool Oliver Kowalke propose a complete implementation of a thread pool with a submit function which evaluate a function asynchronously and returns a task handle. |
| 39 | |
| 40 | Behind all these proposal there is a concept of asynchronous executor, fork-launch-like function and the asynchronous completion token handle. |
| 41 | |
| 42 | || Name || executor || fork-like || ACT || |
| 43 | || Boost.Thread || ?? || thread constructor || thread || |
| 44 | || Boost.!ThreadPool || tp::pool || submit || tp::task || |
| 45 | || N2276 || thread || launch_in_thread || unique_future<T> || |
| 46 | || N2276 || thread_pool || launch_in_pool || unique_future<T> || |
| 47 | || N2185 || ?? || fork || future<T> || |
| 48 | || N1833 || threader || thread || joiner<T> || |
| 49 | |
| 50 | The asynchronous completion token models can follows two interfaces, the thread interface and the unique_future interface. |
| 51 | Some asynchronous completion token handles allows to recover the result of the evaluation of the function (futures), other allows to manage the underlying thread of execution (thread) and some both (joiner and tp::task). |
| 52 | |
| 53 | It seems natural to make a generic fork function that will evaluate a function asynchronously with respect to the calling thread and returns an ACT handle. The following meta-function associated an ACT handle to a asynchronous executor. |
| 54 | |
| 55 | {{{ |
| 56 | #!cpp |
| 57 | template <typename AE, typename T> |
| 58 | struct asynchronous_completion_token { |
| 59 | typedef typename AE::template handle<T>::type type; |
| 60 | }; |
| 61 | }}} |
| 62 | |
| 63 | The result of forking a nullary function by an asynchronous executor is given by the following meta-function: |
| 64 | |
| 65 | {{{ |
| 66 | #!cpp |
| 67 | namespace result_of { |
| 68 | template <typename AE,typename F> |
| 69 | struct fork { |
| 70 | typedef typename asynchronous_completion_token<AE, typename result_of<F()>::type>::type type; |
| 71 | }; |
| 72 | } |
| 73 | }}} |
| 74 | |
| 75 | The default implementation of fork delegates on fork asynchronous executor function. |
| 76 | |
| 77 | {{{ |
| 78 | #!cpp |
| 79 | template< typename AE, typename F > |
| 80 | result_of::fork<AE, F>::type fork( AE& ae, F fn ) { |
| 81 | return ae.fork(fn); |
| 82 | } |
| 83 | }}} |
| 84 | |
| 85 | Forking n-ary functions relies on the nullary version and bind. |
| 86 | |
| 87 | {{{ |
| 88 | #!cpp |
| 89 | template< typename AE, typename F, typename A1, ..., typename An > |
| 90 | asynchronous_completion_token<AE, typename result_of<F(A1,..., An)>::type >::type |
| 91 | fork( AE& ae, F fn, A1 a1, ..., An an ) { |
| 92 | return ae.fork( bind( fn, a1, ..., an ) ); |
| 93 | } |
| 94 | }}} |
378 | | --------------------------------------------------------------------------------------------------- |
379 | | == !AsynchronousExecutors == |
380 | | * '''Suggested by:''' Vicente J. Botet Escriba |
381 | | * '''Description:''' Asynchronous Executors (AE) and Asynchronous Completion Tokens (ACT) in a generic way (or at least this was my intention). The library can be considered as a front-end for several Asynchronous Execution models making it possible to share common algorithms and making easier to switch from an Asynchronous Executors to another. |
382 | | |
383 | | Next follows the motivation for the library and how the library can manage with this concepts. |
384 | | |
385 | | In N1833 - Preliminary Threading Library Proposal for TR2 Kevlin Henney introduce the concept of threader and a function thread that evaluate a function asynchronously and returns a joiner handle. |
386 | | In N2185 - Proposed Text for Parallel Task Execution Peter Dimov introduce a fork function able to evaluate a function asynchronously and returns a future handle. |
387 | | In N2276 - Thread Pools and Futures Anthony William introduce launch_in_thread and launch_in_pool function templates which evaluate a function asynchronously either in a specific thread or a thread pool and returns a unique_future handle. |
388 | | In Boost.ThreadPool Oliver Kowalke propose a complete implementation of a thread pool with a submit function which evaluate a function asynchronously and returns a task handle. |
389 | | |
390 | | Behind all these proposal there is a concept of asynchronous executor, fork-launch-like function and the asynchronous completion token handle. |
391 | | |
392 | | || Name || executor || fork-like || ACT || |
393 | | || Boost.Thread || ?? || thread constructor || thread || |
394 | | || Boost.!ThreadPool || tp::pool || submit || tp::task || |
395 | | || N2276 || thread || launch_in_thread || unique_future<T> || |
396 | | || N2276 || thread_pool || launch_in_pool || unique_future<T> || |
397 | | || N2185 || ?? || fork || future<T> || |
398 | | || N1833 || threader || thread || joiner<T> || |
399 | | |
400 | | The asynchronous completion token models can follows two interfaces, the thread interface and the unique_future interface. |
401 | | Some asynchronous completion token handles allows to recover the result of the evaluation of the function (futures), other allows to manage the underlying thread of execution (thread) and some both (joiner and tp::task). |
402 | | |
403 | | It seems natural to make a generic fork function that will evaluate a function asynchronously with respect to the calling thread and returns an ACT handle. The following meta-function associated an ACT handle to a asynchronous executor. |
404 | | |
405 | | {{{ |
406 | | #!cpp |
407 | | template <typename AE, typename T> |
408 | | struct asynchronous_completion_token { |
409 | | typedef typename AE::template handle<T>::type type; |
410 | | }; |
411 | | }}} |
412 | | |
413 | | The result of forking a nullary function by an asynchronous executor is given by the following meta-function: |
414 | | |
415 | | {{{ |
416 | | #!cpp |
417 | | namespace result_of { |
418 | | template <typename AE,typename F> |
419 | | struct fork { |
420 | | typedef typename asynchronous_completion_token<AE, typename result_of<F()>::type>::type type; |
421 | | }; |
422 | | } |
423 | | }}} |
424 | | |
425 | | The default implementation of fork delegates on fork asynchronous executor function. |
426 | | |
427 | | {{{ |
428 | | #!cpp |
429 | | template< typename AE, typename F > |
430 | | result_of::fork<AE, F>::type fork( AE& ae, F fn ) { |
431 | | return ae.fork(fn); |
432 | | } |
433 | | }}} |
434 | | |
435 | | Forking n-ary functions relies on the nullary version and bind. |
436 | | |
437 | | {{{ |
438 | | #!cpp |
439 | | template< typename AE, typename F, typename A1, ..., typename An > |
440 | | asynchronous_completion_token<AE, typename result_of<F(A1,..., An)>::type >::type |
441 | | fork( AE& ae, F fn, A1 a1, ..., An an ) { |
442 | | return ae.fork( bind( fn, a1, ..., an ) ); |
443 | | } |
444 | | }}} |