Weird behavior with Atomic

Hi all :slight_smile:

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.

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


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?


Expected (i.e. how others do it). From the documentation

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

1 Like