@@ -35,8 +35,8 @@ function TapedTask(tf::TapedFunction, args...)
35
35
close (consume_ch)
36
36
end
37
37
t = TapedTask (task, tf, produce_ch, consume_ch)
38
- # task.storage === nothing && (task.storage = IdDict())
39
- # task.storage[:tapedtask] = t
38
+ task. storage === nothing && (task. storage = IdDict ())
39
+ task. storage[:tapedtask ] = t
40
40
tf. owner = t
41
41
return t
42
42
end
@@ -73,7 +73,9 @@ function increase_counter(t::Tape)
73
73
end
74
74
next_step (t:: TapedTask ) = increase_counter (t. tf. tape)
75
75
76
- # A way (the old way) to impl `produce`, which does NOT
76
+ #=
77
+ # ** Approach (A) to implement `produce`:
78
+ # Make`produce` a standalone instturction. This approach does NOT
77
79
# support `produce` in a nested call
78
80
function internal_produce(instr::Instruction, val)
79
81
tape = gettape(instr)
@@ -91,14 +93,17 @@ function (instr::Instruction{typeof(produce)})()
91
93
args = val(instr.input[1])
92
94
internal_produce(instr, args)
93
95
end
96
+ =#
94
97
95
- #=
96
- # Another way to support `produce` in nested call. This way has its caveat:
98
+ # ** Approach (B) to implement `produce`:
99
+ # This way has its caveat:
97
100
# `produce` may deeply hide in an instruction, but not be an instruction
98
101
# itself, and when we copy a task, the newly copied task will resume from
99
102
# the instruction after the one which contains this `produce` call. If the
100
103
# call to `produce` is not the last expression in the instuction, that
101
104
# instruction will not be whole executed in the copied task.
105
+ # With the abilty to trace into nested function call, we can minimize the
106
+ # limitation of this caveat.
102
107
@inline function is_in_tapedtask ()
103
108
ct = current_task ()
104
109
ct. storage === nothing && return false
@@ -115,7 +120,7 @@ function produce(val)
115
120
take! (ttask. consume_ch) # wait for next consumer
116
121
return nothing
117
122
end
118
- =#
123
+
119
124
120
125
function consume (ttask:: TapedTask )
121
126
if istaskstarted (ttask. task)
0 commit comments