Explicitly Constructing Functors and Runnables
In the following code segment, a functor and threaded runnable instance are explicitly constructed:
Example 2 – Constructing a threaded runnable from a functor
// Construct a functor that invokes hello
RWTFunctor<void()> myFunctor = hello; // 1
// Construct a runnable that invokes functor
RWThreadFunction myThread; // 2
myThread = RWThreadFunction::make(myFunctor); // 3
//1 Constructs a handle instance for a functor object and binds it to the function hello().
//2 Constructs an empty RWThreadFunction handle instance.
//3 Constructs and initializes an RWThreadFunctionImp body instance, then binds that instance to the handle instance, myThread.
The code creates a threaded runnable that, when started, launches a thread that invokes the functor instance to execute the hello() function.