# Is reading from a dict always threadsafe?

**URL:** <https://discourse.julialang.org/t/is-reading-from-a-dict-always-threadsafe/87287>\
**Category:** General Usage\
**Tags:** multithreading\
**Created:** [September 14, 2022, 8:30pm UTC](https://discourse.julialang.org/t/is-reading-from-a-dict-always-threadsafe/87287 "2022-09-14T20:30:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [September 14, 2022, 8:30pm UTC](https://discourse.julialang.org/t/is-reading-from-a-dict-always-threadsafe/87287/1 "2022-09-14T20:30:57Z")

</div>

Writing to a dict is not thread safe, but reading appears to be:

```julia
test_dict = Dict(i => i+1 for i in 1:10_000)
ThreadsX.map(x -> getindex(test_dict, x), 1:10_000)

> 10000-element Vector{Int64}:
     2
     3
     4
     .
     .
     .

```

Is this guaranteed – e.g., can I safely write code that has multiple threads read from a dict, or should I use a mechanism like channels if I need that to work?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 14, 2022, 8:32pm UTC](https://discourse.julialang.org/t/is-reading-from-a-dict-always-threadsafe/87287/2 "2022-09-14T20:32:44Z")

</div>

In general, reads to Dicts (and almost any data structure will be thread safe) if there aren’t any writes.
