# Weird behavior with Atomic

**URL:** <https://discourse.julialang.org/t/weird-behavior-with-atomic/80757>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 9, 2022, 1:35pm UTC](https://discourse.julialang.org/t/weird-behavior-with-atomic/80757 "2022-05-09T13:35:54Z")\
**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:** [May 9, 2022, 1:35pm UTC](https://discourse.julialang.org/t/weird-behavior-with-atomic/80757/1 "2022-05-09T13:35:54Z")

</div>

Hi all 🙂

I’ve got some very weird behavior. Maybe someone knows what’s happening there.

Some code I debug with `@show`. There is nothing between these statements. The code is called in a separate thread.

```julia
@show subscription_manager.threads_to_start[]
@show Threads.atomic_add!(subscription_manager.threads_to_start, -1)

```

Output:

```julia
subscription_manager.threads_to_start[] = 1
Threads.atomic_add!(subscription_manager.threads_to_start, -1) = 1 # here should be = 0

```

How could it be that `Threads.atomic_add!` doesn’t work?

Cheers

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [May 9, 2022, 7:54pm UTC](https://discourse.julialang.org/t/weird-behavior-with-atomic/80757/2 "2022-05-09T19:54:13Z")

</div>

> [@Impressium](#):
>
> How could it be that `Threads.atomic_add!` doesn’t work?

Expected (i.e. how others do it). From the [documentation](https://docs.julialang.org/en/v1/base/multi-threading/)

> Performs `x[] += val` atomically. Returns the **old** value.
