VMS Help
CXXL, task_package
*Conan The Librarian
|
The task package provides coroutine support. A coroutine, or task, is
a subroutine that can suspend execution to allow other tasks to run.
Static data is shared among all tasks; automatic and register data is
allocated separately for each task. Only one task can execute at a
time, even on a multiprocessor system.
Programming with tasks can be particularly appropriate for
simulations, real-time process control, or other applications that can
be reasonably represented as sets of concurrent activities.
This package includes the object and randint classes, and the
subclasses derived from these classes plus the histogram class.
Also, note the following:
o The sched class is intended for use only as a base class.
o The task package makes use of other libraries.
o The task package is not thread safe. You cannot create tasks
simultaneously from different threads.
Header:
#include <task.hxx>
These enums, externs, and typedefs of the task package are used by one
or more classes but they are not members of any particular class.
1.1 - Print Function Values
The following values are used in the verbosity argument to print
member functions:
0 Requests a brief report
CHAIN Requests information about tasks on the object's
remember chain, and about other objects on the
object's o_next chain
STACK Requests information about the run-time stack
VERBOSE Requests detailed information on the class object
1.2 - Queue Mode Values
The following values are used by the qhead and qtail classes for
managing queues:
EMODE Generates a run-time error if full on enqueue or empty
on dequeue
WMODE Suspends task execution if full on enqueue or empty on
dequeue
ZMODE Returns NULL if full on enqueue or empty on dequeue
1.3 - Exception Codes
The following codes handle exceptions for the classes indicated:
E_OLINK = 1 Cannot delete an object with a remembered task
(object class)
E_ONEXT = 2 Cannot delete an object which is on a list
(object class)
E_GETEMPTY = 3 Cannot get an object from an empty queue
(qhead class)
E_PUTOBJ = 4 Cannot put an object into a full queue (qtail
class)
E_PUTFULL = 5 Cannot put an object into a queue if the object
is on another queue (qtail class)
E_BACKOBJ = 6 Cannot putback an object into a queue if the
object is on another queue (qhead class)
E_BACKFULL = 7 Cannot putback an object into a full queue
(qhead class)
E_SETCLOCK = 8 Cannot set the clock after it has advanced
past 0 (sched class)
E_CLOCKIDLE = 9 Cannot advance the clock when clock_task is
RUNNING or TERMINATED (sched class)
E_RESTERM = 10 Cannot resume a TERMINATED task (sched class)
E_RESRUN = 11 Cannot resume a RUNNING task (sched class)
E_NEGTIME = 12 Cannot delay a negative amount of time (sched
class)
E_RESOBJ = 13 Cannot resume a task or timer if it is already
on another queue (sched class)
E_HISTO = 14 Cannot construct a histogram with less than 1
bucket or the left not less than the right
(histogram class)
E_STACK = 15 Cannot extend stack (task class)
E_STORE = 16 Cannot allocate more memory (object, qhead,
qtail, and task classes)
E_TASKMODE = 17 Cannot create a task with a mode other than
DEDICATED or SHARED (task class)
E_TASKDEL = 18 Cannot delete a task which is IDLE or RUNNING
(task class)
E_TASKPRE = 19 Cannot preempt a task which is IDLE or
TERMINATED (task class)
E_TIMERDEL = 20 Cannot delete a timer which is IDLE or RUNNING
(timer class)
E_SCHTIME = 21 Cannot execute something at a time which
already passed (sched class)
E_SCHOBJ = 22 Cannot use class sched other than as a base
class (sched class)
E_QDEL = 23 Cannot delete a queue which has an object in
the queue (qhead and qtail classes)
E_RESULT = 24 Cannot call result() on thistask (task class)
E_WAIT = 25 Cannot call wait() on thistask (task class)
E_FUNCS = 26 Encountered an unexpected exception or access
violation
E_FRAMES = 27 Not used in DEC C++
E_REGMASK = 28 Not used in DEC C++
E_FUDGE_SIZE = 29 Not used in DEC C++
E_NO_HNDLR = 30 Cannot handle a signal for which there is no
handler (Interrupt_handler class)
E_BADSIG = 31 Cannot handle a signal with an invalid signal
number (Interrupt_handler class)
E_LOSTHNDLR = 32 Cannot handle a signal which is not on a stack
of them for the given signal
(Interrupt_handler class)
E_TASKNAMEOVERRUN = 33 Not used in DEC C++
1.4 - Maximum stack size
To keep track of the maximum stack size that can be printed by the
function task::print(), set the _hwm (high-water marking) data
member to a nonzero value before creation of the first task.
Declaration:
extern int _hwm
Objects of this class are generators of exponentially distributed
random numbers.
Objects of this class generate histograms.
Interrupt handlers let tasks wait for external events (system
signals), and allow the declaration of handler functions for these
events.
You can use classes derived from the Interrupt_handler class to
overload the interrupt() function. When the signal is raised, the task
system immediately calls the interrupt() function. The task system
then schedules its own internal interrupt alerter for execution.
Control returns to the task (if any) that was running when the signal
was raised. When control returns to the scheduler, the interrupt
alerter runs and schedules for execution those tasks that were waiting
for the interrupt handler.
If the run chain is empty, the scheduler does not cause the program
to exit if there are any interrupt handlers that have been created but
not yet destroyed.
This class is a base class for many other classes within the task
package. You can also use it to derive user classes to be placed in
the task package's queues and so forth. All objects derived from the
object class can declare the virtual function object::pending(), which
the scheduler uses to determine if an object is ready or not. You can
provide each kind of object with its own method of determining its
state of readiness. Each pending object contains a list (the remember
chain) of the waiting task objects.
This class provides facilities for taking objects off a queue. A
queue is a data structure with an associated list of objects of the
object class, or a class derived from the object class in first-in,
first-out order. All access to a queue is through either the attached
qhead or the attached qtail. You create a queue by creating either a
qhead or a qtail. The other end of the queue is created automatically.
You can then obtain a pointer to the tail with the qhead::tail
function.
Objects have definitions of when they are ready and pending (not
ready). The qhead objects are ready when the queue is not empty and
pending when the queue is empty.
This class provides facilities for putting objects into a queue. A
queue is a data structure with an associated list of objects of the
object class, or a class derived from the object class in first-in,
first-out order. All access to a queue is through either the attached
qhead or the attached qtail. You create a queue by creating either a
qhead or a qtail. The other end of the queue is created automatically.
You can then obtain a pointer to the head with the qtail::head
function.
Objects have definitions of when they are ready and pending (not
ready). The qtail objects are ready when the queue is not full and
pending when the queue is full.
Objects of this class generate uniformly distributed random numbers.
Each random-number generator object produces a sequence that is
independent of other random-number generator objects.
This class provides facilities for checking on the state of a task,
manipulating the simulated clock, canceling a task, and checking on
the result of a task.
You can create instances of classes derived from the sched class, but
not instances of the sched class itself.
All coroutine classes are derived from this class. All work for an
object of a given coroutine type occurs within the constructor for
that type. The coroutine class must be exactly one level of derivation
from the task class. When the object is created, the constructor takes
control and runs until halted by one of the following functions:
wait()
sleep()
resultis()
When a task executes a blocking function on an object that is ready,
the operation succeeds immediately and the task continues running; if
the object is pending, the task waits. Control then returns to the
scheduler, which selects the next task from the ready list or run
chain. When a pending object becomes ready, the system puts any task
waiting for that object back on the run chain.
A task can be in one of the following states:
RUNNING Running or ready to run
IDLE Waiting for a pending object
TERMINATED Completed; not able to resume running (but you can
retrieve the result)
Objects of this class are timers. When a timer is created its state is
RUNNING, and it is scheduled to change its state to TERMINATED after a
specified number of time units. When the timer becomes TERMINATED,
tasks waiting for it are scheduled to resume execution.
Objects of this class generate uniformly distributed random integers
within a given range from a low to a high value.