Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

RWTRunnableIOUFunction<Return>


RWTRunnableIOUFunction<Return> RWRunnable

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Member Functions

Package

Threading

Header File

#include <rw/thread/RWTRunnableIOUFunction.h> 

Description

The RWTRunnableIOUFunction class is a handle class for a 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, and in this case, a return value.

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.

RWTRunnableIOUFunction is used to access a synchronous runnable. A synchronous runnable executes the specified functor using in same thread that calls start(). The result of the functor is returned in the form of an IOU. An IOU may be obtained as soon as the runnable is created. To get the actual result from the IOU you must redeem it, and at that time if the result has not yet been calculated, then the calling thread will block until it has.

Although functors are central to the inner workings of Threading package classes, you may not need to deal with functors directly. Instead, the rwtMakeRunnableIOUFunction() global template functions and macros can build the appropriate functor instance and use it to initialize an RWTRunnableIOUFunction object directly from a function pointer.

Although RWTRunnableIOUFunction is an RWRunnable it does not store exceptions generated by its target function in the same way that other runnables do. Instead of setting the runnable state to RW_THR_EXCEPTION and storing the exception in the runnable, it intercepts the exception and sets it as an exception on the RWTIOUResult to be returned.

One of the effects of this is that callbacks set using the runnable interface of an RWTRunnableIOUFunction and designed to detect the RW_THR_EXCEPTION execution state will not be triggered when the runnable function throws an exception. Another side effect is that, although the runnable terminated because of an exception throw, calling raise() on the runnable will not generate the exception. Instead the IOUResult returned by the function will throw the exception when it is redeemed.

Example

Public Constructors

RWTRunnableIOUFunction(void)
RWTRunnableIOUFunction(const RWTRunnableIOUFunction<Return>& 
                       second)

Public Member Operator

RWTRunnableIOUFunction<Return>&
operator=(const RWTRunnableIOUFunction<Return>& second);
RWTIOUResult<Return>
operator()(void) const;

Public Member Functions

RWTFunctorR0<Return>
getFunctor(void) const
throws(RWTHRInvalidPointer, RWTHRInternalError);
RWTIOUResult<Return>
result(void) const;
void
setFunctor(const RWTFunctorR0<Return>& functor)
throws(RWTHRInvalidPointer, RWTHRInternalError);
void
setIOUEscrow(const RWTIOUEscrow<Return>& escrow)
throws(RWTHRInvalidPointer, RWTHRInternalError);

Static Public Member Functions

static RWTRunnableIOUFunction<Return>
make(void);
static RWTRunnableIOUFunction<Return>
make(const RWTFunctorR0<Return>& functor)
static RWTRunnableIOUFunction<Return>
make(const RWTIOUEscrow<Return>& escrow, 
     const RWTFunctorR0<Return>& functor)

See Also

rwtMakeRunnableIOUFunction, RWTFunctorR0, RWRunnable, RWRunnableHandle



Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.