Threads[Task]
Start
start a new task
Calling Sequence
Parameters
Description
Examples
Compatibility
Start(fcn, arg1, ..., argN)
fcn
-
(appliable) the function to execute in the Task
args1..argsN
(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.
with(Threads[Task]); cont := proc( a, b ) return a + b; end proc;
Continue,Return,Start
cont ≔ proca,breturna+bend proc
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;
task ≔ proci,jlocalk;ifj − i<1000thenreturnadd⁡k,k=i..jelsek ≔ floor⁡1/2*j − 1/2*i+i;Threads:-Task:-Continue⁡cont,Task=task,i,k,Task=task,k+1,jend ifend proc
Start⁡task,1,107
50000005000000
Start⁡cont,Task=task,1,5⁢106,Task=task,5⁢106+1,107
Start⁡cont,Tasks=task,1,5⁢106,5⁢106+1,107
add⁡i,i=1..107
The Threads[Task][Start] command was updated in Maple 15.
See Also
Continue
examples,Task
Task
Task Programming Model
Download Help Document