Simpler case.

julia> function test2()
           @async x=1
           x = 2
       end

test2 (generic function with 1 method)


julia> test2()

ERROR: UndefVarError: x not defined

 in test2 at none:2


Issue created : https://github.com/JuliaLang/julia/issues/11062


On Thu, Apr 30, 2015 at 8:55 AM, Amit Murthy <[email protected]> wrote:

> Yes, this looks like a bug. In fact the below causes an error:
>
> function test2()
>       ref = @spawnat workers()[1] begin
>                x=1
>            end;
>       x=2
> end
>
> Can you open an issue on github?
>
>
> On Thu, Apr 30, 2015 at 7:07 AM, Sam Kaplan <[email protected]>
> wrote:
>
>> Hello,
>>
>> I have the following code example:
>> addprocs(1)
>>
>> function test1()
>>     ref = @spawnat workers()[1] begin
>>         x = 1
>>     end
>>     y = fetch(ref)
>>     @show y
>> end
>>
>> function test2()
>>     ref = @spawnat workers()[1] begin
>>         x = 1
>>     end
>>     x = fetch(ref)
>>     @show x
>> end
>>
>> function main()
>>     test1()
>>     test2()
>> end
>>
>> main()
>>
>> giving the following output:
>> y => 1
>> ERROR: x not defined
>>  in test2 at /tmp/test.jl:12
>>  in main at /tmp/test.jl:21
>>  in include at /usr/bin/../lib64/julia/sys.so
>>  in include_from_node1 at ./loading.jl:128
>>  in process_options at /usr/bin/../lib64/julia/sys.so
>>  in _start at /usr/bin/../lib64/julia/sys.so
>> while loading /tmp/test.jl, in expression starting on line 24
>>
>>
>> Is this a valid error in the code or a bug in Julia?  The error seems to
>> be caused when the variable that is local to the `@spawnat` block has its
>> name mirrored by the variable being assigned to by the `fetch` call.
>>
>> For reference, I am running version 0.3.6:
>>                _
>>    _       _ _(_)_     |  A fresh approach to technical computing
>>   (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
>>    _ _   _| |_  __ _   |  Type "help()" for help.
>>   | | | | | | |/ _` |  |
>>   | | |_| | | | (_| |  |  Version 0.3.6
>>  _/ |\__'_|_|_|\__'_|  |
>> |__/                   |  x86_64-redhat-linux
>>
>>
>> Thanks!
>>
>> Sam
>>
>
>

Reply via email to