run() blocks *its task* until the separate process it invokes completes. 
 If there are other tasks which can proceed it will yield to them as you 
have shown below.

But if you just do run() in the REPL its the same task as the command line, 
so it blocks the command line.

Note that running a separate process is going to take some time, so even in 
the case where the other process is a "fast" thing like `touch` there will 
be a delay during which the run() will yeild (although touch is not *so* 
fast since it does disk IO) .

Cheers
Lex


On Wednesday, April 8, 2015 at 12:33:36 AM UTC+10, Ben Arthur wrote:
>
> spawn() and readandwrite() are documented as being variants of run() which 
> do not block the command line.  yet in an @async, run() seems to yield to 
> other tasks.  to wit:
>
> # bar prints first because it's the first task
> julia> @sync begin 
>    @async println("bar") 
>    @async (run(`sleep 10`);println("foo")) 
>    end 
> bar 
> foo 
> Task (done) @0x00007f87c088fba0 
>
> # but why does bar print first here?
> julia> @sync begin 
>    @async (run(`sleep 10`);println("foo")) 
>    @async println("bar") 
>    end 
> bar 
> foo
> Task (done) @0x00007f87c08b3f60
>
> note that the behavior is the same if i replace the `sleep 10` with a 
> `touch foo`.
>

Reply via email to