# \#multithreading

**URL:** https://discourse.julialang.org/tag/multithreading/100.md

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

---

## [Benchmarking and threads](https://discourse.julialang.org/t/benchmarking-and-threads/138593)

<div class="topic-metadata">

**Author:** [@phma](https://discourse.julialang.org/u/phma)\
**Replies:** 9\
**Last updated:** [August 9, 2026, 9:14am UTC](https://discourse.julialang.org/t/benchmarking-and-threads/138593 "2026-08-09T09:14:02Z")

</div>

In the bench workspace, I have this function: function kaftorTime(textLen::Integer,keyLen::Integer) # in nanoseconds text=fill(0x69,textLen) key=fill(0x96,keyLen) trial=@benchmark kaftorEncrypt!($text,$key) me…

---

## [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…

---

## [Julia-snail in Emacs and multithreading](https://discourse.julialang.org/t/julia-snail-in-emacs-and-multithreading/137761)

<div class="topic-metadata">

**Author:** [@mahmah](https://discourse.julialang.org/u/mahmah)\
**Replies:** 1\
**Last updated:** [June 23, 2026, 2:12pm UTC](https://discourse.julialang.org/t/julia-snail-in-emacs-and-multithreading/137761 "2026-06-23T14:12:33Z")

</div>

How to set up julia-snail so that it launches julia as -t auto? Thanks!

---

## [Thread-safe implementation for simple counter/mean](https://discourse.julialang.org/t/thread-safe-implementation-for-simple-counter-mean/137542)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 21\
**Last updated:** [June 11, 2026, 3:58pm UTC](https://discourse.julialang.org/t/thread-safe-implementation-for-simple-counter-mean/137542 "2026-06-11T15:58:04Z")

</div>

I have a callable which performs an iterative calculation, which is otherwise thread-safe. I would like to keep a statistic of the mean number of iterations that it used, and is thread-safe. Stylized code follows: muta…

---

## [Does the interactive thread have due performance?](https://discourse.julialang.org/t/does-the-interactive-thread-have-due-performance/137568)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 1\
**Last updated:** [June 11, 2026, 3:54pm UTC](https://discourse.julialang.org/t/does-the-interactive-thread-have-due-performance/137568 "2026-06-11T15:54:51Z")

</div>

I have 2 physical chips on my machine, each having 64 physical cores. So there are 2 \* 2 \* 64 = 256 virtual processors. julia\> Sys.cpu\_summary() AMD EPYC 7763 64-Core Processor: speed user ni…

---

## [Writing to a shared buffer in multi-threaded for loop](https://discourse.julialang.org/t/writing-to-a-shared-buffer-in-multi-threaded-for-loop/137373)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 17\
**Last updated:** [June 7, 2026, 5:53pm UTC](https://discourse.julialang.org/t/writing-to-a-shared-buffer-in-multi-threaded-for-loop/137373 "2026-06-07T17:53:38Z")

</div>

I have a for loop that iterates over millions of elements, each of which are processed quickly. Elements update random parts of a shared buffer. I’m trying to parallelize this operation in a performant way. I have consid…

---

## [When could I need more threads than CPU cores, given 1.7+ task migration?](https://discourse.julialang.org/t/when-could-i-need-more-threads-than-cpu-cores-given-1-7-task-migration/137315)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 16\
**Last updated:** [June 5, 2026, 2:36pm UTC](https://discourse.julialang.org/t/when-could-i-need-more-threads-than-cpu-cores-given-1-7-task-migration/137315 "2026-06-05T14:36:24Z")

</div>

Title basically says it all. To elaborate, the number of OS threads running in parallel is at most the number of virtual CPU cores. The reason for having many more threads is that some threads can or must idle, so there…

---

## [Perf Julia@threads behind Numba@njit(parallel=True)](https://discourse.julialang.org/t/perf-julia-threads-behind-numba-njit-parallel-true/137388)

<div class="topic-metadata">

**Author:** [@cheng.wu](https://discourse.julialang.org/u/cheng.wu)\
**Replies:** 17\
**Last updated:** [June 2, 2026, 9:59am UTC](https://discourse.julialang.org/t/perf-julia-threads-behind-numba-njit-parallel-true/137388 "2026-06-02T09:59:33Z")

</div>

(This is a follow up to Julia vs Numba, having created a new discourse account) I came across this article on the performance of Julia vs Python+Numba, and this section interested me. It claims parallel Julia code is qu…

---

## [Can I decide if a program needs thread-safety at compile time based on the threads available by the julia process?](https://discourse.julialang.org/t/can-i-decide-if-a-program-needs-thread-safety-at-compile-time-based-on-the-threads-available-by-the-julia-process/137321)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 7\
**Last updated:** [May 28, 2026, 8:43pm UTC](https://discourse.julialang.org/t/can-i-decide-if-a-program-needs-thread-safety-at-compile-time-based-on-the-threads-available-by-the-julia-process/137321 "2026-05-28T20:43:11Z")

</div>

i.e. can I do something like const needs\_thread\_safety = Threads.nthreads() == 1 ? false : true and then use the constant to compile differently if it is true or false (disabling atomics and/or locks if false)? Or do I…

---

## [Windows 11 KB5089573 multithreading issues](https://discourse.julialang.org/t/windows-11-kb5089573-multithreading-issues/137312)

<div class="topic-metadata">

**Author:** [@arch-dev](https://discourse.julialang.org/u/arch-dev)\
**Replies:** 3\
**Last updated:** [May 28, 2026, 1:21pm UTC](https://discourse.julialang.org/t/windows-11-kb5089573-multithreading-issues/137312 "2026-05-28T13:21:20Z")

</div>

Today, I’ve installed the KB5089573 update which brings the so called “Low Latency Profile” feature to Windows 11 (more information here). Up to now I’ve never had any issues with multithreading. My usage case is a while…

---

## [Dictionary for thread-safe, limited memoization](https://discourse.julialang.org/t/dictionary-for-thread-safe-limited-memoization/137072)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 25\
**Last updated:** [May 27, 2026, 10:14pm UTC](https://discourse.julialang.org/t/dictionary-for-thread-safe-limited-memoization/137072 "2026-05-27T22:14:14Z")

</div>

I am looking for a Dict-like type which allows me to keep only the last N values inserted, for some value of N::Int, is thread-safe. Background: memoization, where the resulting objects are large and I am unlike…

---

## [CUDA.jl with @threads causing memory leak?](https://discourse.julialang.org/t/cuda-jl-with-threads-causing-memory-leak/136853)

<div class="topic-metadata">

**Author:** [@noetheriankoala](https://discourse.julialang.org/u/noetheriankoala)\
**Replies:** 3\
**Last updated:** [April 27, 2026, 10:23pm UTC](https://discourse.julialang.org/t/cuda-jl-with-threads-causing-memory-leak/136853 "2026-04-27T22:23:37Z")

</div>

Hello. First of all, I am using Julia v1.12.6, CUDA v5.11.2, and FLoops v0.2.2. Consider the following code and comments. using CUDA using Base.Threads function func1() A = CuArray{Float64}(undef, 1500, 1500, 1000)…

---

## [Compilation behavior in the multi-threading context](https://discourse.julialang.org/t/compilation-behavior-in-the-multi-threading-context/136632)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 3\
**Last updated:** [April 18, 2026, 3:09pm UTC](https://discourse.julialang.org/t/compilation-behavior-in-the-multi-threading-context/136632 "2026-04-18T15:09:18Z")

</div>

Oftentimes compilation takes some time before running the main code. Given the following code function fn(x, y, z) # some heavy work that needs to be compiled end spawn\_fn(a...) = Threads.@spawn(fn(a...)) function …

---

## [Reusing @local cache when multithreading](https://discourse.julialang.org/t/reusing-local-cache-when-multithreading/136579)

<div class="topic-metadata">

**Author:** [@amousavi](https://discourse.julialang.org/u/amousavi)\
**Replies:** 1\
**Last updated:** [April 6, 2026, 1:30am UTC](https://discourse.julialang.org/t/reusing-local-cache-when-multithreading/136579 "2026-04-06T01:30:17Z")

</div>

Hi everyone! I am trying to update an old project of mine where I have three nested for loops as such: scratch = zeros(Float32, tree\_nodes, nthreads()) collect\_here = zeros(Float32, nthreads()) for i in eachindex(V) @…

---

## [Multithreading on Apple M5 chips](https://discourse.julialang.org/t/multithreading-on-apple-m5-chips/136109)

<div class="topic-metadata">

**Author:** [@chrisnekarda](https://discourse.julialang.org/u/chrisnekarda)\
**Replies:** 4\
**Last updated:** [March 11, 2026, 12:37am UTC](https://discourse.julialang.org/t/multithreading-on-apple-m5-chips/136109 "2026-03-11T00:37:28Z")

</div>

I’m considering upgrading to the new Apple M5-series hardware and have a question regarding how Julia will handle the new core tiers. Previous generations of Apple Silicon had two types of cores, “performance” (P-cores)…

---

## [How to avoid writing code that makes hardware become overheating?](https://discourse.julialang.org/t/how-to-avoid-writing-code-that-makes-hardware-become-overheating/135883)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 7\
**Last updated:** [February 28, 2026, 10:28am UTC](https://discourse.julialang.org/t/how-to-avoid-writing-code-that-makes-hardware-become-overheating/135883 "2026-02-28T10:28:03Z")

</div>

I run julia code (multithreaded) on a Ubuntu machine. The cpu were 2 AMD chips that totally have 256 available threads out of 128 physical cores (i.e. 64 cores per chip entity). (But I find that julia can set thread numb…

---

## [Basic question about thread interaction](https://discourse.julialang.org/t/basic-question-about-thread-interaction/135532)

<div class="topic-metadata">

**Author:** [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Replies:** 3\
**Last updated:** [February 10, 2026, 9:39am UTC](https://discourse.julialang.org/t/basic-question-about-thread-interaction/135532 "2026-02-10T09:39:23Z")

</div>

Hi everyone. I’m trying to learn how to use threads in Julia by comparing them to the Python examples from Ramalho’s Fluent Python book Fluent Python, 2nd Edition \[Book\]. The basic Python example is: import itertools i…

---

## [Is any implementation of sortperm running on multiple threads available?](https://discourse.julialang.org/t/is-any-implementation-of-sortperm-running-on-multiple-threads-available/111853)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 3\
**Last updated:** [February 4, 2026, 2:41pm UTC](https://discourse.julialang.org/t/is-any-implementation-of-sortperm-running-on-multiple-threads-available/111853 "2026-02-04T14:41:03Z")

</div>

As it says: Even experimental code would help. Thanks! Edit: Found this great piece of code: Parallel quicksort openmp - #18 by pitsianis I sort of remembered having seen it, but could not find it again.

---

## [Multi-thread for nested loop with internal conditions, tricky](https://discourse.julialang.org/t/multi-thread-for-nested-loop-with-internal-conditions-tricky/135041)

<div class="topic-metadata">

**Author:** [@apolion](https://discourse.julialang.org/u/apolion)\
**Replies:** 1\
**Last updated:** [January 14, 2026, 7:09am UTC](https://discourse.julialang.org/t/multi-thread-for-nested-loop-with-internal-conditions-tricky/135041 "2026-01-14T07:09:08Z")

</div>

Hello everyone, I am computing some interactions between systems from the results of other simulations, sort of post-processing. As noted in the code, for system 1 I have 1000 simulations (variations), system 2 has 400. …

---

## [Question about data races](https://discourse.julialang.org/t/question-about-data-races/135037)

<div class="topic-metadata">

**Author:** [@BananaMaster3](https://discourse.julialang.org/u/BananaMaster3)\
**Replies:** 1\
**Last updated:** [January 14, 2026, 2:25am UTC](https://discourse.julialang.org/t/question-about-data-races/135037 "2026-01-14T02:25:21Z")

</div>

Say we have a struct Foo: mutable struct Foo dee::Int fee::Int = 3 end We then define an array of Foo’s arrFoo = \[Foo(1), Foo(1), Foo(2), Foo(3)\] Then we have a function that, when given foo and a specific item…

---

## [Does writing in parallel block the whole process?](https://discourse.julialang.org/t/does-writing-in-parallel-block-the-whole-process/134620)

<div class="topic-metadata">

**Author:** [@NonDairyNeutrino](https://discourse.julialang.org/u/NonDairyNeutrino)\
**Replies:** 4\
**Last updated:** [December 19, 2025, 8:37pm UTC](https://discourse.julialang.org/t/does-writing-in-parallel-block-the-whole-process/134620 "2025-12-19T20:37:43Z")

</div>

Say I have a large piece of data data that I want to write or serialize (for speed) to a file file with serialize("path/to/file", data). Done naively, this will block the rest of the program from executing. So it’s simp…

---

## [What is the correct way to use Base.OncePerThread?](https://discourse.julialang.org/t/what-is-the-correct-way-to-use-base-onceperthread/134597)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 7\
**Last updated:** [December 18, 2025, 4:52pm UTC](https://discourse.julialang.org/t/what-is-the-correct-way-to-use-base-onceperthread/134597 "2025-12-18T16:52:42Z")

</div>

I want to use Base.OncePerThread but it’s not clear what the intended usage is. Is the following a correct / safe / intended way to use Base.OncePerThread ? finalset = Set() tempsets = OncePerThread() do return Set…

---

## [Multithreading non-contiguous mapreduction over huge matrices](https://discourse.julialang.org/t/multithreading-non-contiguous-mapreduction-over-huge-matrices/134413)

<div class="topic-metadata">

**Author:** [@noetheriankoala](https://discourse.julialang.org/u/noetheriankoala)\
**Replies:** 5\
**Last updated:** [December 8, 2025, 7:36am UTC](https://discourse.julialang.org/t/multithreading-non-contiguous-mapreduction-over-huge-matrices/134413 "2025-12-08T07:36:45Z")

</div>

Hello! A version of the following function is majorly bottle-necking a project I am working on and I could use help speeding it up. In all the below code, A is an k x n matrix, l is a length-n vector, and q is a length n…

---

## [\`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…

---

## [Multi-threading Heisenbug: code is faster when profiled](https://discourse.julialang.org/t/multi-threading-heisenbug-code-is-faster-when-profiled/133805)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 5\
**Last updated:** [November 28, 2025, 2:01pm UTC](https://discourse.julialang.org/t/multi-threading-heisenbug-code-is-faster-when-profiled/133805 "2025-11-28T14:01:26Z")

</div>

I have some trivially parallelizable for loops that I wanted to speed up using multi-threading, namely using Folds.jls Folds.foreach(). I started julia with julia -t 8 to get one interactive thread and 8 worker threads a…

---

## [Is there any way to use cd with multithreading?](https://discourse.julialang.org/t/is-there-any-way-to-use-cd-with-multithreading/133984)

<div class="topic-metadata">

**Author:** [@eott-siz](https://discourse.julialang.org/u/eott-siz)\
**Replies:** 2\
**Last updated:** [November 21, 2025, 8:00am UTC](https://discourse.julialang.org/t/is-there-any-way-to-use-cd-with-multithreading/133984 "2025-11-21T08:00:53Z")

</div>

I’m currently working on a simulation server for running simulations with our simulation engine. The simulation input is uploaded via a Python flask API, but the simulation code and the code handling execution is in Juli…

---

## [Execute Function for each Julia Thread](https://discourse.julialang.org/t/execute-function-for-each-julia-thread/133889)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 6\
**Last updated:** [November 15, 2025, 7:02am UTC](https://discourse.julialang.org/t/execute-function-for-each-julia-thread/133889 "2025-11-15T07:02:36Z")

</div>

I have an external library which requires thread local resources to function. For every thread Julia creates, it must notify this library via an initialize\_thread\_local() function. Is there a way to run this code for eac…

---

## [Understanding "random" serialization when using @spawn in a "parallel region"](https://discourse.julialang.org/t/understanding-random-serialization-when-using-spawn-in-a-parallel-region/133824)

<div class="topic-metadata">

**Author:** [@mmesiti](https://discourse.julialang.org/u/mmesiti)\
**Replies:** 11\
**Last updated:** [November 13, 2025, 11:59am UTC](https://discourse.julialang.org/t/understanding-random-serialization-when-using-spawn-in-a-parallel-region/133824 "2025-11-13T11:59:50Z")

</div>

I have some Julia (1.10.10) code that I am benchmarking on a HPC cluster node with 76 physical cores, running with 76 threads, and I am seeing HUGE variability between runs with everything equal (same hardware, same code…

---

## [\[ANN\] ZoneProfilers.jl: Another interface for the Tracy profiler](https://discourse.julialang.org/t/ann-zoneprofilers-jl-another-interface-for-the-tracy-profiler/133806)

<div class="topic-metadata">

**Author:** [@nhz2](https://discourse.julialang.org/u/nhz2)\
**Replies:** 0\
**Last updated:** [November 11, 2025, 11:22pm UTC](https://discourse.julialang.org/t/ann-zoneprofilers-jl-another-interface-for-the-tracy-profiler/133806 "2025-11-11T23:22:52Z")

</div>

I have been working on an interface for the tracy profiler to profile a multithreaded program I am working on. There are two closely related packages. ZoneProfilers.jl provides utilities to mark up code and a P…

---

## [Threads.@threads on views into a vector doesn't give much of a speed-up](https://discourse.julialang.org/t/threads-threads-on-views-into-a-vector-doesnt-give-much-of-a-speed-up/133713)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 3\
**Last updated:** [November 6, 2025, 9:16pm UTC](https://discourse.julialang.org/t/threads-threads-on-views-into-a-vector-doesnt-give-much-of-a-speed-up/133713 "2025-11-06T21:16:40Z")

</div>

I am trying to speed my code up using the Threads.@threads macro and splitting an array into multiple views so that each thread works on a separate view, but am not getting the performance gains I had hoped for. Conside…

[Next page](https://discourse.julialang.org/tag/multithreading/100.md?match_all_tags=true&page=1&tags%5B%5D=multithreading)
