to do multiple work asyncronously (sorting vectors, and function calculation mainly (where the calculations is compute or memory bound,at the moment, i can write those operations in the following ways:
- using
Threads.@spawn
_f1 = Threads.@spawn f1(x)
_f2 = Threads.@spawn f2(x)
_f3 = Threads.@spawn f3(x)
y1 = fetch(_f1)
y2 = fetch(_f2)
y3 = fetch(_f3)
There is also this pattern (seems cleaner):
@sync begin
@async y1 = f1(x)
@async y2 = f2(x)
@async y3 = f3(x)
end
for this particular use case, which one is preferred?