RWRunnableTrap RWHandleBase
#include <rw/thread/RWRunnableTrap.h>
RWRunnableTrap allows you to wait for a number of runnables or threads to reach a certain execution state. When you create an RWRunnableTrap you specify the target execution state. This causes any runnable that the trap has been set on to catch the runnable when it reaches the given execution state.
Another thread can get each runnable as it reaches the target execution state by calling the getNext() function of the runnable trap. A runnable may be caught by the trap by calling setTrap() and passing in the target runnable. By default the runnable is caught only once, the first time that it enters the execution state. When you set the trap on a runnable you may specify that the runnable be caught repeatedly, each time that it enters the execution state.
A common usage of an RWRunnableTrap is to wait for a number of threads to complete execution. This allows you to launch and wait for multiple threads without having to keep track of those threads in an array or other data structure. After a thread is created, but before it is started, it can be added to a runnable trap.
The default target execution state is RW_THR_INITIAL which is the state that a runnable reaches when it completes execution.
#include <rw/thread/RWRunnableTrap.h> #include <rw/thread/RWRunnable.h> #include <rw/thread/RWThread.h> #include <rw/thread/rwtMakeThreadFunction.h> RWRunnableTrap rnblTrap = RWRunnableTrap::make(); int i; for (i= 0; i<10; i++) { RWThread thread = rwtMakeThreadFunction(function); rnblTrap.setTrap(thread); // before starting thread! thread.start(); } for (i=0; i<10; i++) { RWRunnable rnbl = rnblTrap.getNext(); rnbl.join(); }
RWRunnableTrap(void);
Constructs an invalid RWRunnableTrap.If the runnable trap is used without it being initialized, an invalid pointer exception will be thrown.
RWRunnableTrap(RWStaticCtor);
Constructs a static RWRunnableTrap.
RWRunnableTrap(const RWRunnableTrap& second);
Copy constructor.
~RWRunnableTrap(void);
Default destructor.
RWRunnableTrap& operator=(const RWRunnableTrap& second)
Assignment operator.
RWRunnable getNext(void);
Gets the next RWRunnable that has entered executionState_. Blocks if no RWRunnable is trapped.
RWWaitStatus getNext(RWRunnable &r, unsigned long milliseconds);
Gets the next RWRunnable that has entered executionState_. Times out after given milliseconds if no RWRunnable is trapped. Returns either RW_THR_TIMEOUT or RW_THR_COMPLETED.
void getNext(RWRunnable& r, RWExecutionState& es);
Gets the next trapped RWRunnable and the execution state that caused it to be trapped.
RWWaitStatus getNext(RWRunnable& r, RWExecutionState& es, unsigned long milliseconds)
Gets the next trapped RWRunnable and the execution state that caused it to be trapped. Times out after given milliseconds if no RWRunnable is trapped. Returns either RW_THR_TIMEOUT or RW_THR_COMPLETED.
RWBoolean isEmpty(void) const;
Returns TRUE if the queue is empty, FALSE otherwise.
static RWRunnableTrap make(unsigned long executionStateMask=RW_THR_INITIAL);
Constructs runnable trap to catch runnables as they reach the given execution state(s). The default is to wait until a runnable finishes execution and returns to its initial state. (See the RWExecutionState enum in RWRunnableHandle.h.)
void setTrap(RWRunnable runnable, RWCallbackScope scope=RW_CALL_ONCE);
Traps the given runnable when it enters executionState_ (that was specified when the runnable trap was created.) An RWCallbackScope may be specified as either RW_CALL_ONCE or RW_CALL_REPEATEDLY. This determines whether the runnable should enter the trap only once, when it enters the target execution state, or repeatedly, each time it enters that state.
RWBoolean tryGetNext(RWRunnable& runnable);
Gets the next runnable to reach the target execution state, if one is available. Returns TRUE and sets the runnable parameter if one could be read, otherwise returns FALSE.
RWBoolean tryGetNext(RWRunnable& runnable, RWExecutionState& es);
Gets the next runnable to reach the target execution state, if one is available. Returns TRUE and sets the runnable parameter if one could be read, otherwise returns FALSE. Sets es to the execution state that tripped the trap.
RWRunnableTrap(RWRunnableTrapImp* runnableTrapImpP);
Constructs a handle from an RWRunnableTrapImp*.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.