Class that calls the result of thread execution and outputs it in a thread safe manner. This class is similar to the std::promise
class of C++11.
More...
#include "nn/nlib/threading/Future.h"
Inherits nn::nlib::threading::detail::PromiseBase< Derived >.
template<class R>
class nn::nlib::threading::Promise< R >
Class that calls the result of thread execution and outputs it in a thread safe manner. This class is similar to the std::promise
class of C++11.
- Template Parameters
-
R | The type of the value to output. You can also specify void . |
- Description
- It is easier to use the
PackagedTask
class instead of using this class directly.
- When you do use this class, use it as follows. Note that a copy constructor and assignment operator are not defined.
void threadFunc(ThreadArg<Promise<int> >::ArgType& ptr) {
ptr->arg1.SetValue(1);
}
....
ThreadArg<Promise<int> >::ArgType p(new ThreadArg<Promise<int> >());
Future<int> myfuture;
p->arg1.GetFuture(&myfuture);
p->func = threadFunc;
Thread th;
th.Start(p);
th.Join();
int result = myfuture.Get();
Definition at line 41 of file Future.h.
◆ GetFuture()
Sets Future
to get the result of execution.
- Parameters
-
- Return values
-
0 | Success. |
EINVAL | Indicates that p is NULL . |
ENOMEM | Indicates that memory allocation failed to store the value. |
Definition at line 323 of file Future.h.
◆ Init()
Initializes the object.
- Return values
-
0 | Success. |
ENOMEM | memory allocation failed. |
EALREADY | Already initialized. |
Definition at line 321 of file Future.h.
◆ SetError()
Sets an error value.
- Parameters
-
- Return values
-
0 | Error value successfully set. |
EALREADY | Error value already set. |
ENOMEM | Indicates that either memory allocation failed or that the Init function was not called ahead of time. |
- Description
- If a nonzero error value has been set, the
Future::Get(R* ptr)
function can return an error value as its return value.
Definition at line 322 of file Future.h.
◆ SetValue()
Sets a value, and makes it possible to use Future
to extract it.
- Parameters
-
[in] | value | The value to set. |
- Return values
-
0 | Success. |
ENOMEM | Indicates that memory allocation failed to store the value. |
EALREADY | Indicates that a value has already been set. |
- The value is set in a thread-safe manner for
Future
.
Definition at line 342 of file Future.h.
◆ swap()
Swaps an object.
- Parameters
-
Definition at line 326 of file Future.h.
The documentation for this class was generated from the following files: