•
|
MapleStartChildTask creates a child task for the currently executing task. This task may start executing as soon as MapleStartChildTask returns. This function should only be called after a continuation task has been created, by calling MapleCreateContinuationTask.
|
•
|
Before using the Task Programming Model in external call, one should first become familiar with the Task Programming in Maple. The external call interface is more complex, so understanding the underlying model first will make the external call interface easier to understand.
|
•
|
In external call a task is a function and a data element. The task function must match the following prototype
|
int (M_DECL *TaskFunction)( void *parent, int arg_number, void *self )
The self parameter is the input data matching the task. The parent parameter is the input data matching the task's parent. If the task wants to return a value to its parent then it is the task's responsibility to update its parent's input data. The arg_number parameter is specified when the child task is created, and allows child tasks to differentiate themselves when updating their parent's input data.
For example:
#include "maplec.h"
|
|
struct TaskStruct {
|
M_INT myData;
|
M_INT parentLeft;
|
M_INT parentRight;
|
};
|
|
int M_DECL TaskFunction( void *parent, int arg_number, void *self )
|
{
|
struct TaskStruct *myArgs;
|
M_INT ret;
|
myArgs = (struct TaskStruct*)self;
|
|
ret = DoWork( myArgs );
|
|
switch( arg_number )
|
{
|
case MAPLE_ROOT_TASK:
|
(int)parent = ret; / Root task /
|
break;
|
|
case 1:
|
((struct TaskStruct*)parent)->parentLeft = ret;
|
break;
|
|
case 2:
|
((struct TaskStruct*)parent)->parentRight = ret;
|
break;
|
}
|
|
return 1;
|
}
|
|
|
Thus when the parent task executes (after all its children have executed) its input data will have been updated by its children.
The task function returns an int, however currently this value is not used.
•
|
After creating the continuation task, child tasks can be started by calling MapleStartChildTask functions.
|
•
|
The MarkTaskFunction function is called if a garbage collection occurs and the continuation task is still valid. The argument passed into MarkTaskFunction is the value passed as self. This allows the programmer the ability to maintain Maple data structures in the task and mark then when garbage collection occurs. See the MapleGcMark help pages for more information on marking.
|