RWThreadFunction RWThread
#include <rw/thread/RWThreadFunction.h>
The RWThreadFunction class is a handle class for a functor-based threaded 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 threaded 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-base runnables allow you to dynamically specify the functions you want to execute when a runnable is started.
RWThreadFunction is used to access a threaded runnable, which creates a new thread to execute the specified functor.
Although functors are central to the inner workings of Threads.h++ , you may not need to deal with functors directly. Instead, the rwtMakeThreadFunction() global template functions and macros can build the appropriate functor instance and use it to initialize an RWThreadFunction object directly from a function pointer.
#include <rw/thread/RWThreadFunction.h> #include <rw/thread/rwtMakeThreadFunction.h> #include <rw/functor/functor0.h> void foo(int i) { cout << i << endl; } int main() { // Create an RWThreadFunction that calls foo. RWThreadFunction threadfunc = rwtMakeThreadFunction(foo,7); RWFunctor0 functor; threadfunc.start(); // spawns a thread that prints 7 threadfunc.join(); // Create a functor directly, passing 11 as client data. functor = rwtMakeFunctor0((void(*)(void))0, foo, 11); // Set threadfunc to use the new functor: threadfunc.setFunctor(functor); threadfunc.start(); // spawns a thread that prints 11 threadfunc.join(); }
RWThreadFunction(void)
Constructs an empty RWThreadFunction handle instance.
RWThreadFunction(const RWThreadFunction& second)
Binds a new handle to the runnable instance, if any, pointed to by the handle second.
RWThreadFunction& operator=(const RWThreadFunction& second)
Binds this to the runnable instance, if any, pointed to by the handle second.
RWFunctor0 getFunctor(void) const;
Gets the current functor instance, if any, associated with the runnable. Possible exceptions include RWTHRInvalidPointer and RWTHRInternalError.
void setFunctor(const RWFunctor0& functor);
Sets the functor to be executed by this runnable. Possible exceptions include RWTHRInvalidPointer and RWTHRInternalError.
static RWThreadFunction make(void);
Constructs and returns an RWThreadFunction object with an undefined functor. The setFunctor() member must be used to define a functor prior to starting.
static RWThreadFunction make(const RWFunctor0& functor);
Constructs and returns an RWRunnableFunction that will execute the specified functor when started.
static RWThreadFunction make(const RWFunctor0& functor, const RWThreadAttribute& attr);
Constructs and returns an RWRunnableFunction that will execute the specified functor when started. A new thread will be created using the thread attributes given by attr.
static RWThreadFunction make(const RWThreadAttribute& attr);
Constructs and returns an RWThreadFunction object with an undefined functor. The setFunctor() member must be used to define a function prior to starting. A new thread will be created using the attributes given by attr.
rwtMakeThreadFunction, RWFunctor0, RWThread
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.