I want to do multi Task (A,B) pairs which have no connections with each other. Each Task A include multi Task a. Task A has to be done before B start in the same one (A,B) pair. So it’s like
@async for loop do multi (A,B)s
@sync do one (A,B)
@async for loop do Task A
do Task a
do Task B
how can I achieve this?
I have tried:
b = Vector{String}(undef, 6)
ta = @async for i in range(1, length(b))
a = Vector{String}(undef, 6)
@async for j in range(1, length(a)) # task A
a[j] = "hello "
sleep(1) # task a
end
#task B
b[i] = prod(a) * "world!"
sleep(1)
end
@time wait(ta)
# fail: Task B does not wait for task A in the same pair.
b = Vector{String}(undef, 6)
ta = @async for i in range(1, length(b))
a = Vector{String}(undef, 6)
for j in range(1, length(a)) # task A
@async begin
a[j] = "hello "
sleep(1) # task a
end
end
#task B
b[i] = prod(a) * "world!"
sleep(1)
end
@time wait(ta)
# fail: Task B does not wait for task A in the same pair.
b = Vector{String}(undef, 6)
ta = @async for i in range(1, length(b))
a = Vector{String}(undef, 6)
taA= @async for j in range(1, length(a)) # task A
a[j] = "hello "
sleep(1) # task a
end
wait(taA)
#task B
b[i] = prod(a) * "world!"
sleep(1)
end
@time wait(ta)
# fail: multi (A,B) pairs not async to each other.
b = Vector{String}(undef, 6)
ta = @async for i in range(1, length(b))
a = Vector{String}(undef, 6)
taA = @async for j in range(1, length(a)) # task A
a[j] = "hello "
sleep(1) # task a
end
while !istaskdone(taA)
sleep(0.5)
end
b[i] = prod(a) * "world!"
sleep(1)
end
@time wait(ta)
# fail: multi (A,B) pairs not async to each other.