# \#atomic

**URL:** https://discourse.julialang.org/tag/atomic/481.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Is there a way to tell at runtime if a struct field is atomic?](https://discourse.julialang.org/t/is-there-a-way-to-tell-at-runtime-if-a-struct-field-is-atomic/138377)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 6\
**Last updated:** [July 23, 2026, 5:36am UTC](https://discourse.julialang.org/t/is-there-a-way-to-tell-at-runtime-if-a-struct-field-is-atomic/138377 "2026-07-23T05:36:30Z")

</div>

When one makes a struct like mutable struct Status @atomic st::Symbol # other fields end Is there a way to tell that st is a special field? Since fieldtypes gives no additional information. julia\> fieldtypes(S…

---

## [Migrating CUDA.jl atomic operations to ParallelStencil.jl using Atomix.jl?](https://discourse.julialang.org/t/migrating-cuda-jl-atomic-operations-to-parallelstencil-jl-using-atomix-jl/136710)

<div class="topic-metadata">

**Author:** [@Ludovic\_Dumoulin](https://discourse.julialang.org/u/Ludovic_Dumoulin)\
**Replies:** 2\
**Last updated:** [April 14, 2026, 1:57pm UTC](https://discourse.julialang.org/t/migrating-cuda-jl-atomic-operations-to-parallelstencil-jl-using-atomix-jl/136710 "2026-04-14T13:57:33Z")

</div>

Hello, I am currently porting my code from CUDA.jl to ParallelStencil.jl. While I have successfully managed the transition for mixed Float64 and ComplexF64 types, I have run into a challenge replacing CUDA-specific atom…

---

## [\`Threads.atomic\_cas!\`, \`Threads.SpinLock\`, and \`@atomic\` documentation](https://discourse.julialang.org/t/threads-atomic-cas-threads-spinlock-and-atomic-documentation/134369)

<div class="topic-metadata">

**Author:** [@Marco\_Lombardi](https://discourse.julialang.org/u/Marco_Lombardi)\
**Replies:** 2\
**Last updated:** [December 5, 2025, 2:16pm UTC](https://discourse.julialang.org/t/threads-atomic-cas-threads-spinlock-and-atomic-documentation/134369 "2025-12-05T14:16:55Z")

</div>

Reading the Julia manual, I see that there is a “mild” deprecation for a series of atomic-related functions, including Threads.atomic\_cas!. I understand this is in favor of the @atomic macro, which is apparently more gra…

---

## [\[ANN\] YetAnotherSimulationSuite.jl: An atomic simulation suite](https://discourse.julialang.org/t/ann-yetanothersimulationsuite-jl-an-atomic-simulation-suite/132398)

<div class="topic-metadata">

**Author:** [@Cavenfish](https://discourse.julialang.org/u/Cavenfish)\
**Replies:** 2\
**Last updated:** [September 15, 2025, 2:56pm UTC](https://discourse.julialang.org/t/ann-yetanothersimulationsuite-jl-an-atomic-simulation-suite/132398 "2025-09-15T14:56:10Z")

</div>

YetAnotherSimulationSuite.jl (YASS) aims to offer users a simple, intuitive and easy-to-use atomic simulation suite. It draws inspiration from Python’s ASE, but is intended to be faster and offer users more flexibility. …

---

## [Read/write locks and wait/wake on atomics: are there Julia futexes?](https://discourse.julialang.org/t/read-write-locks-and-wait-wake-on-atomics-are-there-julia-futexes/130602)

<div class="topic-metadata">

**Author:** [@iago-lito](https://discourse.julialang.org/u/iago-lito)\
**Replies:** 1\
**Last updated:** [July 10, 2025, 11:08am UTC](https://discourse.julialang.org/t/read-write-locks-and-wait-wake-on-atomics-are-there-julia-futexes/130602 "2025-07-10T11:08:57Z")

</div>

I wished there was a read-write lock in Julia but I couldn’t find any. But there are atomics so I figured I could write one myself, inspiring from this (inspiring) book on the nasty-gritty low-level details of concurrenc…

---

## [Cannot manage to use CUDA.atomic\_add!](https://discourse.julialang.org/t/cannot-manage-to-use-cuda-atomic-add/130328)

<div class="topic-metadata">

**Author:** [@Ludovic\_Dumoulin](https://discourse.julialang.org/u/Ludovic_Dumoulin)\
**Replies:** 4\
**Last updated:** [June 30, 2025, 7:24pm UTC](https://discourse.julialang.org/t/cannot-manage-to-use-cuda-atomic-add/130328 "2025-06-30T19:24:40Z")

</div>

Hello, I want to place particles into a 10x10 grid. To do this, I would like to use CUDA.atomic\_add!() to count how many particles land in each cell. Here is a minimal example: using CUDA function kernel\_test\_atomicad…

---

## [How to properly do thread-safe element-wise mutation on atomic fields?](https://discourse.julialang.org/t/how-to-properly-do-thread-safe-element-wise-mutation-on-atomic-fields/130138)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 4\
**Last updated:** [June 23, 2025, 7:57pm UTC](https://discourse.julialang.org/t/how-to-properly-do-thread-safe-element-wise-mutation-on-atomic-fields/130138 "2025-06-23T19:57:52Z")

</div>

MWE: julia\> mutable struct Atomic{T} @atomic a::T end julia\> obj1 = Atomic(collect(1:4)) Atomic{Vector{Int64}}(\[1, 2, 3, 4\]) julia\> obj1.a .= 2 4-element Vector{Int64}: 2 2 2 2 Unlike directly c…

---

## [Incrementing AtomicMemory{SVector}](https://discourse.julialang.org/t/incrementing-atomicmemory-svector/121378)

<div class="topic-metadata">

**Author:** [@tverho](https://discourse.julialang.org/u/tverho)\
**Replies:** 3\
**Last updated:** [October 16, 2024, 2:06pm UTC](https://discourse.julialang.org/t/incrementing-atomicmemory-svector/121378 "2024-10-16T14:06:58Z")

</div>

I’m trying to use the new \`AtomicMemory in 1.11 to increment entries of a vector in an atomic way. However, the following example hangs: using StaticArrays mem = AtomicMemory{SVector{2,Float64}}(undef, 10) # Initialize…

---

## [Does \`@atomic\` syntax support non-primitive-type fields in a \`mutable struct\`?](https://discourse.julialang.org/t/does-atomic-syntax-support-non-primitive-type-fields-in-a-mutable-struct/116703)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 2\
**Last updated:** [July 6, 2024, 7:30pm UTC](https://discourse.julialang.org/t/does-atomic-syntax-support-non-primitive-type-fields-in-a-mutable-struct/116703 "2024-07-06T19:30:30Z")

</div>

I was reading the documentation on per-field atomics, and it seems that @atomic can be put in front of any type of field (unlike Base.Threads.Atomic) as long as the struct is mutable. I also tested it with the following …

---

## [Combining results from threaded calculations](https://discourse.julialang.org/t/combining-results-from-threaded-calculations/115753)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 7\
**Last updated:** [June 19, 2024, 2:51pm UTC](https://discourse.julialang.org/t/combining-results-from-threaded-calculations/115753 "2024-06-19T14:51:50Z")

</div>

I have a calculation which uses a buffer for a subset of a cohort of agents (in the MWE below, each has different \\kappa), steps this forward from a given value in time, calculates some aggregate at each point in time. …

---

## [Lock free sorted linked list](https://discourse.julialang.org/t/lock-free-sorted-linked-list/115157)

<div class="topic-metadata">

**Author:** [@melevy](https://discourse.julialang.org/u/melevy)\
**Replies:** 18\
**Last updated:** [June 6, 2024, 7:29pm UTC](https://discourse.julialang.org/t/lock-free-sorted-linked-list/115157 "2024-06-06T19:29:10Z")

</div>

Hi! I’m trying to implement a lock free sorted linked list as shown in 9.8 Nonblocking synchronization of the book titled The art of multiprocessor programming. I need something like AtomicMarkableReference or maybe…

---

## [Hazard pointers - in C++26 vs Julia - concurrency/atomics e.g. for UInt128](https://discourse.julialang.org/t/hazard-pointers-in-c-26-vs-julia-concurrency-atomics-e-g-for-uint128/108866)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 4\
**Last updated:** [January 24, 2024, 5:30am UTC](https://discourse.julialang.org/t/hazard-pointers-in-c-26-vs-julia-concurrency-atomics-e-g-for-uint128/108866 "2024-01-24T05:30:00Z")

</div>

I hadn’t seen this concept, and wanted to let others know, and ask how it contrasts to Julia, but to answer my own question: In a multithreaded computing environment, hazard pointers are one approach to solving the pr…

---

## [Why so few methods defined for \`Atomic\` types?](https://discourse.julialang.org/t/why-so-few-methods-defined-for-atomic-types/96960)

<div class="topic-metadata">

**Author:** [@adienes](https://discourse.julialang.org/u/adienes)\
**Replies:** 0\
**Last updated:** [April 2, 2023, 1:51am UTC](https://discourse.julialang.org/t/why-so-few-methods-defined-for-atomic-types/96960 "2023-04-02T01:51:10Z")

</div>

I am trying to use Atomic wrapped types, but I find there are very few methods defined; I assuming this is intentional, but I’d be curious to hear more about the limitations that prevent these from being included! A lis…

---

## [CUDA atomic add for ForwardDiff duals?](https://discourse.julialang.org/t/cuda-atomic-add-for-forwarddiff-duals/85968)

<div class="topic-metadata">

**Author:** [@Mark\_Lau](https://discourse.julialang.org/u/Mark_Lau)\
**Replies:** 2\
**Last updated:** [August 19, 2022, 5:59pm UTC](https://discourse.julialang.org/t/cuda-atomic-add-for-forwarddiff-duals/85968 "2022-08-19T17:59:41Z")

</div>

Hi everyone, I’ve been trying to auto differentiate some code that runs on the GPU using ForwardDiff. Some of the kernels perform an atomic addition operation via CUDA.@atomic, but that doesn’t seem to be supported for F…

---

## [CUDA.jl - Atomic Addition Error To A Sparse Array Inside CUDA Kernel](https://discourse.julialang.org/t/cuda-jl-atomic-addition-error-to-a-sparse-array-inside-cuda-kernel/78789)

<div class="topic-metadata">

**Author:** [@moukann](https://discourse.julialang.org/u/moukann)\
**Replies:** 4\
**Last updated:** [March 31, 2022, 11:18am UTC](https://discourse.julialang.org/t/cuda-jl-atomic-addition-error-to-a-sparse-array-inside-cuda-kernel/78789 "2022-03-31T11:18:47Z")

</div>

Hello all, I am trying to assemble many individual elements of a huge system to a global system. The global system is sparse, It is a certain thing. Also it is wasteful to store all zero elements in memory, I just need …

---

## [Different calculation results when using CPU vs. GPU with CUDA.jl](https://discourse.julialang.org/t/different-calculation-results-when-using-cpu-vs-gpu-with-cuda-jl/77150)

<div class="topic-metadata">

**Author:** [@Mari](https://discourse.julialang.org/u/Mari)\
**Replies:** 2\
**Last updated:** [March 2, 2022, 4:14pm UTC](https://discourse.julialang.org/t/different-calculation-results-when-using-cpu-vs-gpu-with-cuda-jl/77150 "2022-03-02T16:14:29Z")

</div>

Hi everyone, I am rather new to GPU programming and I am having difficulty understanding why I get different results when running a function on GPU vs. CPU. The function involves atomic operation, and even running it on…

---

## [How to append elements to a CuArray or delete some entries from it in GPU kernel function](https://discourse.julialang.org/t/how-to-append-elements-to-a-cuarray-or-delete-some-entries-from-it-in-gpu-kernel-function/77180)

<div class="topic-metadata">

**Author:** [@Mari](https://discourse.julialang.org/u/Mari)\
**Replies:** 1\
**Last updated:** [March 2, 2022, 10:26am UTC](https://discourse.julialang.org/t/how-to-append-elements-to-a-cuarray-or-delete-some-entries-from-it-in-gpu-kernel-function/77180 "2022-03-02T10:26:49Z")

</div>

Hi everyone, I am looking for a way to be able to efficiently append or delete some entries of a CuArray in the kernels being run on GPU . Also I guess that “append” and “delete” must be perfumed atomically. I am rather…

---

## [Vector of Atomics](https://discourse.julialang.org/t/vector-of-atomics/64984)

<div class="topic-metadata">

**Author:** [@nabla](https://discourse.julialang.org/u/nabla)\
**Replies:** 3\
**Last updated:** [August 13, 2021, 8:27am UTC](https://discourse.julialang.org/t/vector-of-atomics/64984 "2021-08-13T08:27:19Z")

</div>

I’m aware of the Atomic{Int8} type, which wraps an Int8 into an atomically modifiable value. Internally, this is a mutable struct containing the Int8, and it seems to be the only possibility since by nature the Int8 must…

---

## [Copy an atomic variable as a regular variable](https://discourse.julialang.org/t/copy-an-atomic-variable-as-a-regular-variable/66117)

<div class="topic-metadata">

**Author:** [@matthiasbe](https://discourse.julialang.org/u/matthiasbe)\
**Replies:** 1\
**Last updated:** [August 10, 2021, 9:57am UTC](https://discourse.julialang.org/t/copy-an-atomic-variable-as-a-regular-variable/66117 "2021-08-10T09:57:38Z")

</div>

Hello, I am trying to read the value of an atomic (shared) variable as a local (on the current thread) variable. Here is what I tried. julia\> a = Threads.Atomic{Int}(2) Base.Threads.Atomic{Int64}(2) julia\> b = conver…

---

## [Scattered Atomic Writes Into Array](https://discourse.julialang.org/t/scattered-atomic-writes-into-array/46990)

<div class="topic-metadata">

**Author:** [@cshenton](https://discourse.julialang.org/u/cshenton)\
**Replies:** 6\
**Last updated:** [September 21, 2020, 3:41pm UTC](https://discourse.julialang.org/t/scattered-atomic-writes-into-array/46990 "2020-09-21T15:41:06Z")

</div>

I’m porting some OpenCL code that does scattered atomic writes. These writes are quite sparse, meaning that threads rarely try to write cache lines at the same time. I’m trying to figure out how to do this in Julia but …
