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

Online Help

All Products    Maple    MapleSim


Threads[Task]

  

Start

  

start a new task

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

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

Parameters

fcn

-

(appliable) the function to execute in the Task

args1..argsN

-

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

Description

• 

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.

Examples

with(Threads[Task]);
cont := proc( a, b )
   return a + b;
end proc;

Continue,Return,Start

contproca,breturna+bend proc

(1)

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

taskproci&comma;jlocalk&semi;ifji<1000thenreturnaddk&comma;k&equals;i..jelsekfloor1&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

(2)

Starttask&comma;1&comma;107

50000005000000

(3)

Startcont&comma;Task=task&comma;1&comma;5106&comma;Task=task&comma;5106+1&comma;107

50000005000000

(4)

Startcont&comma;Tasks=task&comma;1&comma;5106&comma;5106+1&comma;107

50000005000000

(5)

addi&comma;i=1..107

50000005000000

(6)

Compatibility

• 

The Threads[Task][Start] command was updated in Maple 15.

See Also

Continue

examples,Task

Task

Task Programming Model