start a new task - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Multithreaded Programming : Task : Threads/Task/Start

Threads[Task][Start] - start a new task

Calling Sequence

Start(fcn, arg1,  ..., argN)




(appliable) the function to execute in the Task



(anything) the arguments to fcn or the specification of child tasks



The Start function creates a new invocation of the Task Model.  Start creates a root task and then starts executing tasks until the current invocation exits, either because the all the tasks complete or because the Return function is called.  The return value of Start is the value returned by the final task or the value passed into Return.


The Start function is part of the Task Programming Model.


If no child tasks are specified, then Start creates one task which evaluates fnc( args11...argsN ).  


If child tasks are specified, then Start creates one task for each child, and a continuation task with fnc as the continuation function. The value of fnc is either a procedure or the name of a predefined continuation function.


The two predefined continuation functions are passed and null


passed returns the arguments that were passed into it.


null returns NULL.


An argument to Start of the form


Task = [ cfcn, carg1 ... cargn ]


creates a child task that executes the following command.


cfcn( carg1 ... cargn )


An argument to Start of the form:


Tasks = [ cfcn, [c1args] ... [cnargs] ]


behaves as if multiple Task arguments of the form


Task = [ cfcn, c1args ], Task = [ cfcn, c2args ], ... Task = [ cfcn, cnargs ]


had been given.  Thus, it creates tasks to execute the following commands.


cfcn( c1args ), cfcn( c2args ) ... cfcn( cnargs )


The return value of a child task is passed to the continuation function in the child's position in its argument sequence.


Arguments not of the form described above are passed to the continuation function fcn as arguments in the corresponding positions.


If child tasks are created as part of the call to Start, the continuation task will not start executing until all of its child tasks have completed.


cont := proc( a, b )
   return a + b;
end proc;


cont:=proca,breturna+bend proc


task := proc( i, j )
   local k;
   if ( j-i < 1000 ) then
       return add( k, k=i..j );
       k := floor( (j-i)/2 )+i;
       Continue( cont, Task=[ task, i, k ], Task=[ task, k+1, j ] );
   end if;
end proc;

task:=proci&comma;jlocalk&semi;ifji<1000thenreturnaddk&comma;k&equals;i..jelsek:=floor1&sol;2&ast;j1&sol;2&ast;i&plus;i&semi;`Threads:-Task`:-Continuecont&comma;Task&equals;task&comma;i&comma;k&comma;Task&equals;task&comma;k&plus;1&comma;jend ifend proc














See Also

Continue, examples,Task, Task, Task Programming Model

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam