# Multi-Threading: Threads.Atomic update value

**URL:** <https://discourse.julialang.org/t/multi-threading-threads-atomic-update-value/50737>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [November 25, 2020, 10:28am UTC](https://discourse.julialang.org/t/multi-threading-threads-atomic-update-value/50737 "2020-11-25T10:28:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [November 25, 2020, 10:28am UTC](https://discourse.julialang.org/t/multi-threading-threads-atomic-update-value/50737/1 "2020-11-25T10:28:28Z")

</div>

What’s the difference between

- `a[] = true` and
- `Threads.atomic_xchg!(a, true)`

for `a = Threads.Atomic{Bool}(false)`?

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [November 25, 2020, 5:26pm UTC](https://discourse.julialang.org/t/multi-threading-threads-atomic-update-value/50737/2 "2020-11-25T17:26:25Z")

</div>

I think the important difference is the return value. In the first case, the return value will be `true`; assignment just returns the value assigned.

In the second case, assuming a single threaded program, the value will be `false` since `atomic_xchg!` returns the old value of the reference. In a multi-threaded program where several threads execute `atomic_xchg!`, only one (the first to get there) will see `false`, the others will all see `true` since they see the result of the first `atomic_xchg!`.
