# How to understand code availability of @spawn

**URL:** https://discourse.julialang.org/t/how-to-understand-code-availability-of-spawn/5468
**Category:** General Usage
**Tags:** question, parallel
**Created:** [August 19, 2017, 9:02pm UTC](https://discourse.julialang.org/t/how-to-understand-code-availability-of-spawn/5468 "2017-08-19T21:02:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)
#### Post date: [August 19, 2017, 9:02pm UTC](https://discourse.julialang.org/t/how-to-understand-code-availability-of-spawn/5468/1 "2017-08-19T21:02:57Z")

</div>

In official documentation, two examples are used:

1. 

```julia
julia> function rand2(dims...)
           return 2*rand(dims...)
       end

julia> rand2(2,2)
2×2 Array{Float64,2}:
 0.153756 0.368514
 1.15119 0.918912

julia> fetch(@spawn rand2(2,2))
ERROR: RemoteException(2, CapturedException(UndefVarError(Symbol("#rand2"))
[...]

```

1. 

```julia
julia> A = rand(1000,1000);

julia> Bref = @spawn A^2;

[...]

julia> fetch(Bref);

```

These two examples seem to be very similiar. However, in the first example, `rand2` is not available on worker’s process while in the second example, `A` is available on worker’s process. The only difference is `rand2` is a function and `A` is a variable. What’s the essential difference between a function and a variable such that they behave differently in macro @spawn?

---

<div class="post-metadata">

### Author: ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)
#### Post date: [August 19, 2017, 9:08pm UTC](https://discourse.julialang.org/t/how-to-understand-code-availability-of-spawn/5468/2 "2017-08-19T21:08:00Z")

</div>

Sorry, I noticed immediately the following section says Global variables are treated differently.

How can I delete the post?
