Skip to content

Commit 9883cc3

Browse files
author
KDr2
committed
use approach B to impl produce
1 parent 9478efc commit 9883cc3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/tapedtask.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function TapedTask(tf::TapedFunction, args...)
3535
close(consume_ch)
3636
end
3737
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
4040
tf.owner = t
4141
return t
4242
end
@@ -73,7 +73,9 @@ function increase_counter(t::Tape)
7373
end
7474
next_step(t::TapedTask) = increase_counter(t.tf.tape)
7575

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
7779
# support `produce` in a nested call
7880
function internal_produce(instr::Instruction, val)
7981
tape = gettape(instr)
@@ -91,14 +93,17 @@ function (instr::Instruction{typeof(produce)})()
9193
args = val(instr.input[1])
9294
internal_produce(instr, args)
9395
end
96+
=#
9497

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:
97100
# `produce` may deeply hide in an instruction, but not be an instruction
98101
# itself, and when we copy a task, the newly copied task will resume from
99102
# the instruction after the one which contains this `produce` call. If the
100103
# call to `produce` is not the last expression in the instuction, that
101104
# 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.
102107
@inline function is_in_tapedtask()
103108
ct = current_task()
104109
ct.storage === nothing && return false
@@ -115,7 +120,7 @@ function produce(val)
115120
take!(ttask.consume_ch) # wait for next consumer
116121
return nothing
117122
end
118-
=#
123+
119124

120125
function consume(ttask::TapedTask)
121126
if istaskstarted(ttask.task)

0 commit comments

Comments
 (0)