# ERROR: UndefRefError: access to undefined reference

**URL:** https://discourse.julialang.org/t/error-undefreferror-access-to-undefined-reference/68168
**Category:** General Usage
**Tags:** question
**Created:** [September 14, 2021, 7:28pm UTC](https://discourse.julialang.org/t/error-undefreferror-access-to-undefined-reference/68168 "2021-09-14T19:28:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)
#### Post date: [September 14, 2021, 7:28pm UTC](https://discourse.julialang.org/t/error-undefreferror-access-to-undefined-reference/68168/1 "2021-09-14T19:28:14Z")

</div>

How to eliminate this error  
`ERROR: UndefRefError: access to undefined reference`

```julia
a = 280
A = 1:a
for a in A 
         RandDeviation[a] = rand()
     end

```

---

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [September 14, 2021, 7:50pm UTC](https://discourse.julialang.org/t/error-undefreferror-access-to-undefined-reference/68168/2 "2021-09-14T19:50:13Z")

</div>

It looks that more context is needed to solve this question. I would expect an `UndefVarError` if `RandDeviation` were an undefined variable. But if what you get is an `UndefRefError` is because there is some object there with an undefined field you are trying to access.

What’s `typeof(RandDeviation)`?

---

<div class="post-metadata">

### Author: ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)
#### Post date: [August 30, 2025, 1:46am UTC](https://discourse.julialang.org/t/error-undefreferror-access-to-undefined-reference/68168/3 "2025-08-30T01:46:43Z")

</div>

Today I triggered the same error

```julia
nested task error: UndefRefError: access to undefined reference
    Stacktrace:
     [1] getindex
       @ .\essentials.jl:917 [inlined]
     [2] pop!(a::Vector{Function})
       @ Base .\array.jl:1584
     [3] (::var"#13#16")()
       @ Main .\REPL[9]:9

```

when I was doing `_ = pop!(a)`.

It turns out that I forgot the thread safety—having thread 1 do `push!(a, _)` while thread 2 doing `_ = pop!(a)`. After adding a Reentrantlock the Error disappears.
