Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Threads Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

RWRunnableServer

Module:  Threads   Package:  Threading


RWRunnableServer RWThread

Local Index

Members

Header File

#include <rw/thread/RWRunnableServer.h>

Description

The runnable server may be used alone, or within a class for an active object class implementation. The runnable server object, when started, waits for other threads to enqueue runnable objects that they would like the server thread to execute for them. Each runnable object that the server finds in its internal queue is dequeued and started. The runnable server does not join with the runnables it starts. The runnable server continues to dequeue runnables and execute them until stopped, interrupted, or canceled.

Runnables may be enqueued with a guard functor, or a priority value, or both.

The server uses the guard functor to determine whether the associated runnable is currently eligible for retrieval and execution. A guarded runnable is not retrieved by the server until that runnable is the first runnable in the queue whose guard evaluates to true. Using guards to block runnable execution is important when implementing active objects; guards can be used to insure that the active object maintains consistent state and preserves any necessary invariants.

The priority value is used during write operations to determine a runnable's insertion point within the server's input queue, such that the set of un-processed and eligible runnables will be retrieved in priority order by the server.

The RWRunnable::requestCancellation() function should be used if the server thread is to stop execution as soon as possible without dequeuing and dispatching any additional runnables.

The RWRunnable::requestInterrupt() function can be used to temporarily suspend execution of the server thread.

An active object implementation using this class defines a client interface with member functions that simply produce "runnable functor" objects (see RWRunnableFunction.h and RWTRunnableIOUFunction.h) which, when invoked, execute some corresponding private or local member function within the active object instance. The public members pass the runnable functors to the server thread by calling the enqueue() member, which stores the runnables in a queue. The client interface member function then returns to its caller.

Runnables that use IOUs can be used to represent a future return value or result of the asynchronous active object operation. In this situation, the client interface would create the appropriate IOU-capable runnable object, enqueue the runnable for execution, retrieve the runnable's IOU result, and return that IOU to the caller. The caller could then redeem that IOU at some point in the future.

Example

The following is a skeleton of an active object class implemented using an RWRunnableServer. For a complete active object example, refer to activobj.cpp in the threxam directory.

Static Member Functions

static RWRunnableServer
make();
static RWRunnableServer
make(size_t maxCapacity);
static RWRunnableServer
make(const RWThreadAttribute& serverThreadAttr);
static RWRunnableServer
make(const RWThreadAttribute& serverThreadAttr,
size_t maxCapacity);

Public Constructors

RWRunnableServer();
RWRunnableServer(const RWRunnableServer& second);

Public Destructors

~RWRunnableServer();

Public Member Operator

RWRunnableServer&
operator=(const RWRunnableServer& second);

Public Member Functions

void
checkGuards();
void
enqueue(const RWRunnable& runnable);
RWWaitStatus
enqueue(const RWRunnable& runnable,
unsigned long milliseconds);
void
enqueue(const RWRunnable& runnable, 
        const RWRunnableGuard& guard);
RWWaitStatus
enqueue(const RWRunnable& runnable,
const RWRunnableGuard& guard
unsigned long milliseconds);
void
enqueue(long priority,
const RWRunnable& runnable);
RWWaitStatus
enqueue(long priority,
const RWRunnable& runnable,
unsigned long milliseconds);
void
enqueue(long priority,
const RWRunnable& runnable, const RWRunnableGuard& guard);
RWWaitStatus
enqueue(long priority,
const RWRunnable& runnable,
const RWRunnableGuard& guard
unsigned long milliseconds);
size_t
getCapacity() const;
size_t
setCapacity(size_t maxCapacity);
void
stop();

Protected Constructor

RWRunnableServer(RWRunnableServerImp* threadImpP);

See Also

RWRunnable, RWThread, RWServerPool



Previous fileTop of DocumentContentsIndex pageNext file

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.