Class that wraps a function to run in a different thread, and gets the return value in a thread safe manner. This class is similar to the std::packaged_task
class of C++11.
More...
#include "nn/nlib/threading/Future.h"
template<class T>
class nn::nlib::threading::PackagedTask< T >
Class that wraps a function to run in a different thread, and gets the return value in a thread safe manner. This class is similar to the std::packaged_task
class of C++11.
- Template Parameters
-
T | Function type. Instantiate by writing in the form of int(int, int) . Up to five arguments may be used, and using the void type as a return value is supported. |
- Description
- Supports functions with up to five arguments. Each function may access the data members
arg1
, arg2
, arg3
, arg4
, arg5
.
- Instantiate the template as shown below.
int myplus(int x, int y) { return x + y; }
.....
PackagedTask<int(int, int)> task(myplus);
int arg1 = ....;
int arg2 = ....;
Future<int> myfuture;
task.GetFuture(&myfuture);
Thread th;
th.Join();
int result = myfuture.Get();
Definition at line 914 of file Future.h.
template<class T>
template<class R >
Sets Future
to get the result of execution.
- Template Parameters
-
- Parameters
-
- Return values
-
0 | Success. |
EINVAL | Indicates that p is NULL . |
ENOMEM | Indicates that memory allocation failed to store the value. |
- Description
- Gets
Future
from the Promise
of the object. The result may be acquired from Future
immediately after the functions run by PackagedTask
are completed. You can use this function if the thread is not joined or detached.
template<class T>
template<class FUNC >
Performs initialization.
- Template Parameters
-
FUNC | Type of object that can call a function pointer, and similar. |
- Parameters
-
[in] | func | Object that may call a function pointer or similar. |
- Returns
- Returns
0
on success.
The documentation for this class was generated from the following files: