Question: Problem of Task function

In the following task procedure, when i>1, it works well,but if i=1, the task(M,1,5) returns error

restart

with(Threads[Task])

[Continue, Return, Start]

(1)

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

proc (a, b) return a+b end proc

(2)

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

proc (a, i, j) local k; if j-i <= 3 then return add(a[r], r = i .. j) else k := ceil((1/2)*j-(1/2)*i)+i; Threads:-Task:-Continue(cont, Task = [task, a, i, k], Task = [task, a, k+1, j]) end if end proc

(3)

M := Vector(10, proc (i) options operator, arrow; i end proc):

task(M, 1, 5)

Error, (in Threads:-Task:-Continue) Continue called outside of the Task Queue

 

task(M, 2, 5)

14

(4)

task(M, 5, 5)

5

(5)

``



Download task.mw

Please Wait...