iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Multi-threaded processing helpers

Functions

template<typename Function , typename... Args>
std::future< typename
std::result_of< Function(Args...)>
::type > 
nrt::async (std::launch policy, Function &&fn, Args &&...args)
 
template<typename Function , typename... Args>
std::future< typename
std::result_of< Function(Args...)>
::type > 
nrt::async (Function &&fn, Args &&...args)
 
std::future< void > nrt::groupAsync (std::vector< std::function< void()> > const &jobs)
 The groupAsync method is a way to spawn multiple threads simultaneously. More...
 

Function Documentation

template<typename Function , typename... Args>
std::future< typename std::result_of< Function(Args...)>::type > nrt::async ( std::launch  policy,
Function &&  fn,
Args &&...  args 
)
inline

Behaves exactly like std::async except that it will use an extensible thread pool for asynchronous launching if NRT_USE_STD_ASYNC is false

This function is used to launch a new thread of execution, running the passed function on the given arguments. This variant uses a thread pool (if enabled) that grows as more threads are created and that recycles threads that have completed, if the launch policy is async. If NRT_USE_STD_ASYNC is true, the async behavior will fall back to whatever the used standard library implements.

This is an an attempt to reduce the CPU cost of creating lots of new threads. nrt::async is used extensively by the NRT Blackboard.

Parameters
policyThe launch policy. If deferred, will exact exactly like std::async with deferred. If async, the thread will launch in a thread pool
fnThe function
argsThe function arguments
Returns
A future to the async function
Examples:
tests/test-Async.C.

Definition at line 74 of file AsyncImpl.H.

Referenced by nrt::async(), and nrt::MessageCheckerCore< Checking >::check().

template<typename Function , typename... Args>
std::future< typename std::result_of< Function(Args...)>::type > nrt::async ( Function &&  fn,
Args &&...  args 
)
inline

Behaves as if calling nrt::async with the flags std::launch::async (i.e. async will be preferred, if available)

Definition at line 65 of file AsyncImpl.H.

References nrt::async().

std::future<void> nrt::groupAsync ( std::vector< std::function< void()> > const &  jobs)

The groupAsync method is a way to spawn multiple threads simultaneously.

The advantage of using groupAsync rather than just looping over many calls to std::async is that groupAsync returns a single std::future<void> which will block on a call to wait() until all of the jobs have finished running.

Examples:
tests/test-ThreadPool.C.