The RWRunnableFunction class is a handle class for functor-based runnable objects.
A runnable object provides the basic mechanisms used to create, control, and monitor the threads of execution within your application. Runnables are used to define the task or activity to be performed by a thread.
Each runnable object is reference-counted; a runnable body instance keeps a count of the number of handles that currently reference it. A runnable object is deleted when the last handle that references the body is deleted.
A functor-based runnable accepts a functor object for execution. A functor is an object used to encapsulate a function call. Each functor keeps a pointer to the function and copies of the argument values that are to be passed to the function. Invoking a functor produces a call to the function.
A functor-based runnable simply redefines the basic run()
member to invoke a functor instance stored within the runnable. With this capability, you do not have to resort to sub-classing or other intrusive techniques to customize the execution behavior of a runnable. The functor-based runnables allow you to dynamically specify the functions you want to execute when a runnable is started.
RWRunnableFunction is used to access a synchronous runnable, which executes the specified functor in the same thread that calls start().
- Example
#include <rw/thread/RWRunnableFunction.h>
#include <rw/functor/RWTFunctor.h>
#include <rw/functor/rwBind.h>
void foo(int i) { std::cout << i << std::endl; }
int main() {
RWTFunctor<void()> functor =
rwBind(foo, 11);
return 0;
}
Handle class for functor-based, runnable objects.
Definition RWRunnableFunction.h:86
static RWRunnableFunction make()
void setFunctor(const RWTFunctor< void()> &functor)
RWCompletionState start()
auto rwBind(C &&c, As &&... args)
Binds a callable and arguments into a callable object.
Definition rwBind.h:74