Consider the following piece of code entered at the REPL:
x=false
function c()
global x
sleep(5)
x=true
end
function b()
sleep(1)
@async c()
end
function a()
global x
x=false
@sync @async b()
return x
end
When I call a(), I am surprised that it returns false, rather than true ---
the global x, does become true some while (5 seconds I suppose) later. It
seems that the @sync, waits for @async b() to complete, but not for the
@async c() that b calls.
In the manual, the documentation for @sync states that it waits for all
"dynamically-enclosed uses of @async" [and some other things] are
complete. I was expecting that the nested @async c(), would have counted
as "dynamically-enclosed". This expectation is bolstered when I read in
the documentation for @async that "Additionally it adds the task to the set
of items that the nearest enclosing @sync waits for", where is the nearest
enclosing @sync, if not the one I expect?
Is this a bug in Julia, or the intended behaviour?
Thanks,
Devin.