#include <common.h>
Public Types | |
typedef functor_traits< Ftor >::functor_type | functor_type |
Static Public Member Functions | |
static functor_type | wrap_subthreads (Ftor aFtor, Thr &) |
Normally, a functor has a method 'operator()()', for execution. In our framework, a functor which can be executed in parallel, has a method 'operator()( Threads tree ). We apply this convention to the functors wrapping the STL algorithms.
So, when a functor is to be executed in parallel, we have on one hand the 'threadable' functor object, and on the other hand, a bag of threads, in a data structure called a 'thread tree'. Both are then encapsulated into a new type of 'plain' functor.
Storing threads in trees is for implementing recursive multithreading.
In the most general case, the thread tree has aonly one level : Each functor will be executed by only one sub-thread, and there will be no recursive multi-threading. We then return the same type of ftor, which allows to benefit from the existing optimizations, designed for sequential execution.
'threadify_t' transforms a 'threadable' functor, into a 'plain functor, by creating an object which stores the thread tree which will be later used.
typedef functor_traits< Ftor >::functor_type rpa::threadify_t< Ftor, Thr >::functor_type |
In the general case, the set of sub-threads is just a linear sequence, modelized by its number and the begin iterator. In such a case, the functor type is not changed.
static functor_type rpa::threadify_t< Ftor, Thr >::wrap_subthreads | ( | Ftor | aFtor, | |
Thr & | ||||
) | [inline, static] |
The functor itself is not changed : This is why we cannot fully encapsulate the functor into a class because, if this functor is a simple function pointer, the result will stay as such, i.e. very light and fast.