MapleCreateContinuationTask - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


MapleCreateContinuationTask

Create a continuation task

 

Calling Sequence

Parameters

Description

Calling Sequence

MapleCreateContinuationTask(kv, int (M_DECL *TaskFunction)( void *, int , void * ), void *self, void (M_DECL *MarkTaskFunction)( void * ) )

Parameters

kv

-

kernel handle of type MKernelVector

TaskFunction

-

a pointer to the function to execute as the continuation task

self

-

the argument to pass into the continuation task

MarkTaskFunction

-

the function called when a garbage collection occurs

Description

• 

MapleCreateContinuationTask creates a continuation task for the currently executing task.  After a continuation task has been created, child tasks may be started by calling MapleStartChildTask.

• 

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 for the task to be executed.  The parent parameter is the input data for the task's parent.  If the task wants to pass a value to its parent, it is the task's responsibility to update its parent's input data.  The value for the arg_number parameter is the value given to the arg_number parameter of MapleStartChildTask, when the current task was created, or the predefined value MAPLE_ROOT_TASK if the task is the root task.

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.

• 

If TaskFunction, self and MarkTaskFunction are all NULL, then a continuation task will be created that does not run any user code when executed.

• 

For a complete example, see the OpenMaple/C/TaskProgramming page.

See Also

CustomWrapper

define_external

OpenMaple

OpenMaple/C/API

OpenMaple/C/Examples

OpenMaple/C/MapleStartChildTask

OpenMaple/C/MapleStartRootTask

OpenMaple/C/MapleTaskReturn