Functor-Based Runnables
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.
The Functor package functors are an ideal mechanism for defining the work to be performed by a runnable. Each functor instance is invoked using a common, inherited interface that remains the same regardless of the actual function signature or argument values.
A functor-based runnable redefines the run() member to invoke a functor instance stored within the runnable. With this capability, you do not have to sub-class or use 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.
The functor-based runnables include:
*RWRunnableFunction — A synchronous runnable class that uses a functor to execute a function whose return value, if any, can be ignored.
*RWTRunnableIOUFunction — A synchronous class that uses a functor to execute a function whose return value is to be captured in an IOU. IOUs are a mechanism used to retrieve and wait for the result of an asynchronous operation. See The IOU Classes of the Interthread Communication Package for more information.
*RWThreadFunction — An asynchronous, threaded runnable that creates a new thread to invoke a functor that executes a function whose return value, if any, can be ignored.
*RWTThreadIOUFunction — An asynchronous, threaded runnable that creates a new thread to invoke a functor that executes a function whose return value is to be captured in an IOU.
For more information on functor-based runnables, see Creating Functor-based Runnables. For more information on functors, see Chapter 8, The Functor Package.