# \#threads

**URL:** https://discourse.julialang.org/tag/threads/398.md

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

---

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

---

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

---

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

---

## [Will my variable be modified in a \`do\` block? Very subtle to anticipate](https://discourse.julialang.org/t/will-my-variable-be-modified-in-a-do-block-very-subtle-to-anticipate/131124)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 13\
**Last updated:** [July 28, 2025, 11:28am UTC](https://discourse.julialang.org/t/will-my-variable-be-modified-in-a-do-block-very-subtle-to-anticipate/131124 "2025-07-28T11:28:09Z")

</div>

I notice this difference julia\> Threads.nthreads() 4 julia\> my\_lock = Threads.ReentrantLock() ReentrantLock(nothing, 0x00000000, 0x00, Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing…

---

## [Will \`@info\` corrupt \`Threads.@threads for\`?](https://discourse.julialang.org/t/will-info-corrupt-threads-threads-for/131805)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 18\
**Last updated:** [August 26, 2025, 3:18pm UTC](https://discourse.julialang.org/t/will-info-corrupt-threads-threads-for/131805 "2025-08-26T15:18:53Z")

</div>

My configuration is julia\> Threads.nthreads() 4 julia\> Threads.nthreads(:default) 4 I have a function function parallel\_CG!(B, θ, β, μ, ν) for ite = ... ... for ba = ... sub\_j\_vec = .…

---

## [Trying to parallelize using CUSOLVERRF.jl with @threads](https://discourse.julialang.org/t/trying-to-parallelize-using-cusolverrf-jl-with-threads/131457)

<div class="topic-metadata">

**Author:** [@mhunke](https://discourse.julialang.org/u/mhunke)\
**Replies:** 7\
**Last updated:** [August 19, 2025, 9:09am UTC](https://discourse.julialang.org/t/trying-to-parallelize-using-cusolverrf-jl-with-threads/131457 "2025-08-19T09:09:29Z")

</div>

Hi everyone, I’m working with CUSOLVERRF.jl to solve multiple sparse linear systems on the GPU, using the high-level RFLU API: GitHub - exanauts/CUSOLVERRF.jl: A Julia wrapper for cusolverRF All systems share the same …

---

## [No more threadid indexing? \[thread-local storage\]](https://discourse.julialang.org/t/no-more-threadid-indexing-thread-local-storage/131535)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 36\
**Last updated:** [August 15, 2025, 5:12am UTC](https://discourse.julialang.org/t/no-more-threadid-indexing-thread-local-storage/131535 "2025-08-15T05:12:13Z")

</div>

I am implementing multi-threaded scientific software, an so far it works quite well. But now I am told that thread-local storage is no longer supported by Julia. Well, it still works, even under Julia 1.12rc1, but i am …

---

## [Threads with Channels sometimes lead to weird code excecution](https://discourse.julialang.org/t/threads-with-channels-sometimes-lead-to-weird-code-excecution/130975)

<div class="topic-metadata">

**Author:** [@ncxst](https://discourse.julialang.org/u/ncxst)\
**Replies:** 11\
**Last updated:** [July 24, 2025, 12:23pm UTC](https://discourse.julialang.org/t/threads-with-channels-sometimes-lead-to-weird-code-excecution/130975 "2025-07-24T12:23:14Z")

</div>

Background story I had the problem, that I wanted to generate a certain object from random seeds, which only with a very low probability gives me the result I want. Too speed the calculation up I wanted to parallelize th…

---

## [Problem with running tests in VSCode under Ubuntu (any packages)](https://discourse.julialang.org/t/problem-with-running-tests-in-vscode-under-ubuntu-any-packages/128642)

<div class="topic-metadata">

**Author:** [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Replies:** 1\
**Last updated:** [May 2, 2025, 10:25pm UTC](https://discourse.julialang.org/t/problem-with-running-tests-in-vscode-under-ubuntu-any-packages/128642 "2025-05-02T22:25:48Z")

</div>

For example: (@v1.11) pkg\> test Revise Testing Revise ... Testing Running tests... ERROR: julia: -t,--threads=\<n\>\[,auto|\<m\>\]; n must be an integer \>= 1 ERROR: Package Revise errored during testing The same er…

---

## [Threads are not speeding up computation a lot](https://discourse.julialang.org/t/threads-are-not-speeding-up-computation-a-lot/126305)

<div class="topic-metadata">

**Author:** [@Nyan](https://discourse.julialang.org/u/Nyan)\
**Replies:** 70\
**Last updated:** [March 20, 2025, 6:00am UTC](https://discourse.julialang.org/t/threads-are-not-speeding-up-computation-a-lot/126305 "2025-03-20T06:00:03Z")

</div>

Hi. I googled and read many things about this topic, but cannot figure up what is the problem, and why I see no meaningful speedup for my code. My code: module Keygen using Base.Threads using Base.Iterators include("./…

---

## [Controlling @threads (or similar) parallelism level](https://discourse.julialang.org/t/controlling-threads-or-similar-parallelism-level/126754)

<div class="topic-metadata">

**Author:** [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Replies:** 4\
**Last updated:** [March 10, 2025, 12:45pm UTC](https://discourse.julialang.org/t/controlling-threads-or-similar-parallelism-level/126754 "2025-03-10T12:45:12Z")

</div>

I have a function which is, abstracting, Threads.@threads for i in 1:length(chunk) memory\_intensive\_computation(chunk\[i\]) end I don’t know a priori how memory intensive the computation will be, though I can assume …

---

## [Reduce allocations & lock conflicts and speed up when using multithreads](https://discourse.julialang.org/t/reduce-allocations-lock-conflicts-and-speed-up-when-using-multithreads/125749)

<div class="topic-metadata">

**Author:** [@Stephen](https://discourse.julialang.org/u/Stephen)\
**Replies:** 1\
**Last updated:** [February 10, 2025, 2:11pm UTC](https://discourse.julialang.org/t/reduce-allocations-lock-conflicts-and-speed-up-when-using-multithreads/125749 "2025-02-10T14:11:41Z")

</div>

Hello there, performance enhancement help wanted: ▶ Initial function which gives 309.934138 seconds (5.00 M allocations: 1.982 GiB, 0.23% gc time, 2007 lock conflicts, 0.52% compilation time) 48-element Vector{String}: …

---

## [@threads in for loop and push! in if statement](https://discourse.julialang.org/t/threads-in-for-loop-and-push-in-if-statement/124916)

<div class="topic-metadata">

**Author:** [@Stephen](https://discourse.julialang.org/u/Stephen)\
**Replies:** 6\
**Last updated:** [January 20, 2025, 1:19am UTC](https://discourse.julialang.org/t/threads-in-for-loop-and-push-in-if-statement/124916 "2025-01-20T01:19:21Z")

</div>

Hello there, I’m using @threads to accelerate my for loop, I don’t know how to push! a variable in if , I ask ChatGPT, it gives the code as following: # Initialize an empty array to store symbols, shared across threads …

---

## [Why can Julia spawn new processes but not new threads?](https://discourse.julialang.org/t/why-can-julia-spawn-new-processes-but-not-new-threads/123267)

<div class="topic-metadata">

**Author:** [@NonDairyNeutrino](https://discourse.julialang.org/u/NonDairyNeutrino)\
**Replies:** 1\
**Last updated:** [November 30, 2024, 5:10am UTC](https://discourse.julialang.org/t/why-can-julia-spawn-new-processes-but-not-new-threads/123267 "2024-11-30T05:10:57Z")

</div>

With Distributed.jl, you can create new worker processes easily with addprocs (each of which can have multiple threads), but once a Julia process starts you can’t add more threads to that process; why?

---

## [Is it possible to avoid these excess allocations when using @batch or @threads?](https://discourse.julialang.org/t/is-it-possible-to-avoid-these-excess-allocations-when-using-batch-or-threads/122208)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 4\
**Last updated:** [November 8, 2024, 10:37am UTC](https://discourse.julialang.org/t/is-it-possible-to-avoid-these-excess-allocations-when-using-batch-or-threads/122208 "2024-11-08T10:37:37Z")

</div>

It took some effort to come up with a short MWE for this issue. The goal is to avoid a few small allocations when mutating (an argument of an inner function) in parallel: MWEusing BenchmarkTools, Parameters, Polyester, …

---

## [Timing compilation when using threads](https://discourse.julialang.org/t/timing-compilation-when-using-threads/121001)

<div class="topic-metadata">

**Author:** [@theogf](https://discourse.julialang.org/u/theogf)\
**Replies:** 0\
**Last updated:** [October 7, 2024, 11:56am UTC](https://discourse.julialang.org/t/timing-compilation-when-using-threads/121001 "2024-10-07T11:56:38Z")

</div>

Is it possible to correctly measure compilation time when using Tasks on separate threads? I have tried using the 1.11 @timed but get inconsistent timings for the compilation time. I also don’t have a clear picture of …

---

## [Manage tasks from Threads.@spawn without using map()](https://discourse.julialang.org/t/manage-tasks-from-threads-spawn-without-using-map/118493)

<div class="topic-metadata">

**Author:** [@felipe\_1](https://discourse.julialang.org/u/felipe_1)\
**Replies:** 16\
**Last updated:** [August 27, 2024, 2:55pm UTC](https://discourse.julialang.org/t/manage-tasks-from-threads-spawn-without-using-map/118493 "2024-08-27T14:55:57Z")

</div>

Hi, I need to analyze a long vector and calculate the occurrences of certain letters, as it will be very long it will be better to use parallel processing for this. The thing is, I can do this with map(), storing tasks…

---

## [Julia -\> C (Pthread) -\> Julia Saxpy with Threads](https://discourse.julialang.org/t/julia-c-pthread-julia-saxpy-with-threads/118097)

<div class="topic-metadata">

**Author:** [@miniskar](https://discourse.julialang.org/u/miniskar)\
**Replies:** 1\
**Last updated:** [August 12, 2024, 4:49pm UTC](https://discourse.julialang.org/t/julia-c-pthread-julia-saxpy-with-threads/118097 "2024-08-12T16:49:28Z")

</div>

I am having an C++ library environment where I am supposed to call Julia kernel (example SAXPY) with threading. A minimum work example to illustrate the issue is given below. The Julia main() function calls ‘call\_direc…

---

## [Communicating across worker processes](https://discourse.julialang.org/t/communicating-across-worker-processes/118017)

<div class="topic-metadata">

**Author:** [@ndehngwa](https://discourse.julialang.org/u/ndehngwa)\
**Replies:** 2\
**Last updated:** [August 12, 2024, 5:30am UTC](https://discourse.julialang.org/t/communicating-across-worker-processes/118017 "2024-08-12T05:30:45Z")

</div>

Hello. I just got into julia and i could use some help. I am trying to create an application that listens for instructions form the command line and sends them to a worker process. The worker process performs some compu…

---

## [Parallelization of long- and short running tasks](https://discourse.julialang.org/t/parallelization-of-long-and-short-running-tasks/99936)

<div class="topic-metadata">

**Author:** [@unis](https://discourse.julialang.org/u/unis)\
**Replies:** 8\
**Last updated:** [July 16, 2024, 6:21pm UTC](https://discourse.julialang.org/t/parallelization-of-long-and-short-running-tasks/99936 "2024-07-16T18:21:56Z")

</div>

Assume you have a long-running, “expensive” function, e.g., function longrun() dim = 20000 A = rand(dim,dim)/dim A^256 end which may take a few minutes to complete, and a function that is short-running a…

---

## [\[pre-ANN\] DataFlowTasks.jl: a package for inferring task dependencies based on data annotations](https://discourse.julialang.org/t/pre-ann-dataflowtasks-jl-a-package-for-inferring-task-dependencies-based-on-data-annotations/87559)

<div class="topic-metadata">

**Author:** [@maltezfaria](https://discourse.julialang.org/u/maltezfaria)\
**Replies:** 8\
**Last updated:** [June 3, 2024, 7:01am UTC](https://discourse.julialang.org/t/pre-ann-dataflowtasks-jl-a-package-for-inferring-task-dependencies-based-on-data-annotations/87559 "2024-06-03T07:01:44Z")

</div>

Dear Julia community, Together with @ffevotte , @LaurentPlagne , and Vincent Sivadon, we have put together a package (DataFlowTasks) for automatically inferring implicit Task dependencies from explicitly annotated data …

---

## [How to convert a thread-parallelized code into a core-parallelized code?](https://discourse.julialang.org/t/how-to-convert-a-thread-parallelized-code-into-a-core-parallelized-code/114406)

<div class="topic-metadata">

**Author:** [@Uranium238](https://discourse.julialang.org/u/Uranium238)\
**Replies:** 3\
**Last updated:** [May 19, 2024, 7:06am UTC](https://discourse.julialang.org/t/how-to-convert-a-thread-parallelized-code-into-a-core-parallelized-code/114406 "2024-05-19T07:06:44Z")

</div>

This post can be thought as a successor to an old series of posts that I had made where the motive was to improve the performance and eventually parallelize a code that consisted primarily of matrix operations, the end g…

---

## [Inconsistent CPU utilisation in @threads loops](https://discourse.julialang.org/t/inconsistent-cpu-utilisation-in-threads-loops/110512)

<div class="topic-metadata">

**Author:** [@ysh](https://discourse.julialang.org/u/ysh)\
**Replies:** 20\
**Last updated:** [February 23, 2024, 8:55pm UTC](https://discourse.julialang.org/t/inconsistent-cpu-utilisation-in-threads-loops/110512 "2024-02-23T20:55:43Z")

</div>

Consider a MWE where some moderately-heavy calculations are performed in a parallel loop. Here, I am simulating the calculations by doing eigen: using LinearAlgebra, Random BLAS.set\_num\_threads(1) # turn off BLAS parall…

---

## [Julia code becomes slower on running on supercomputers and does not scale well when parallelizing with Base.Threads](https://discourse.julialang.org/t/julia-code-becomes-slower-on-running-on-supercomputers-and-does-not-scale-well-when-parallelizing-with-base-threads/108439)

<div class="topic-metadata">

**Author:** [@Uranium238](https://discourse.julialang.org/u/Uranium238)\
**Replies:** 73\
**Last updated:** [January 22, 2024, 1:21pm UTC](https://discourse.julialang.org/t/julia-code-becomes-slower-on-running-on-supercomputers-and-does-not-scale-well-when-parallelizing-with-base-threads/108439 "2024-01-22T13:21:22Z")

</div>

This question is a continuation / generalization of my previous question. My end goal is to write a parallelized code where the main time taking part is Matrix multiplication and inversion. As per the advice of @ufechner…

---

## [Best strategy to choose the number of gc threads on a cluster](https://discourse.julialang.org/t/best-strategy-to-choose-the-number-of-gc-threads-on-a-cluster/107596)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 2\
**Last updated:** [December 14, 2023, 9:45am UTC](https://discourse.julialang.org/t/best-strategy-to-choose-the-number-of-gc-threads-on-a-cluster/107596 "2023-12-14T09:45:04Z")

</div>

I have a multithreaded code that I am running on a cluster using Julia v1.10, and it allocates many temporary arrays. The computation is quite linear algebra heavy, and I would like to keep freeing memory from time to ti…

---

## [Threads.@spawn weird ouput message](https://discourse.julialang.org/t/threads-spawn-weird-ouput-message/94548)

<div class="topic-metadata">

**Author:** [@CeterisPartybus](https://discourse.julialang.org/u/CeterisPartybus)\
**Replies:** 6\
**Last updated:** [December 12, 2023, 1:57am UTC](https://discourse.julialang.org/t/threads-spawn-weird-ouput-message/94548 "2023-12-12T01:57:51Z")

</div>

Hi everyone, I am testing two parallel versions of my loop - one with @threads and one with @spawn. Weirdly, @spawn finishes in a fraction of the time @threads needs, makes much fewer allocations, and gives me this weir…

---

## [Performance issue with multithreaded computation with matrix operations at its heart (Threads.@threads vs. BLAS threads)](https://discourse.julialang.org/t/performance-issue-with-multithreaded-computation-with-matrix-operations-at-its-heart-threads-threads-vs-blas-threads/106043)

<div class="topic-metadata">

**Author:** [@HanD](https://discourse.julialang.org/u/HanD)\
**Replies:** 7\
**Last updated:** [November 13, 2023, 5:00pm UTC](https://discourse.julialang.org/t/performance-issue-with-multithreaded-computation-with-matrix-operations-at-its-heart-threads-threads-vs-blas-threads/106043 "2023-11-13T17:00:05Z")

</div>

While trying to speed up a long computation with chunking more threads on it, I ran into an interesting problem. I found several related threads here, but I couldn’t find a convincing answer, nor a solution to my issue. …

---

## [Using an assignment outside of threaded for loop degraded performance by a huge amount](https://discourse.julialang.org/t/using-an-assignment-outside-of-threaded-for-loop-degraded-performance-by-a-huge-amount/105552)

<div class="topic-metadata">

**Author:** [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Replies:** 10\
**Last updated:** [October 30, 2023, 11:51pm UTC](https://discourse.julialang.org/t/using-an-assignment-outside-of-threaded-for-loop-degraded-performance-by-a-huge-amount/105552 "2023-10-30T23:51:05Z")

</div>

I created an MWE for this question, in practice the only difference between the fs functions is that T = Int is introduced in different scopes, however the first two versions are very slow: using Base.Threads: @threads,…

---

## [What is the mechanics of \`copy\` in the thread-parallization by \`Threads.@spawn\`? Or: Problems with copy arrays in thread parallelism](https://discourse.julialang.org/t/what-is-the-mechanics-of-copy-in-the-thread-parallization-by-threads-spawn-or-problems-with-copy-arrays-in-thread-parallelism/104729)

<div class="topic-metadata">

**Author:** [@draftman9](https://discourse.julialang.org/u/draftman9)\
**Replies:** 1\
**Last updated:** [October 8, 2023, 4:40pm UTC](https://discourse.julialang.org/t/what-is-the-mechanics-of-copy-in-the-thread-parallization-by-threads-spawn-or-problems-with-copy-arrays-in-thread-parallelism/104729 "2023-10-08T16:40:19Z")

</div>

I hope to implement a thread-parallel sample, a common example in solving time-dependent evolution problems (e.g. main\_serial in the code. Generate a matrix arr\_task over time. This matrix is updated over loop/time and …

---

## [Multithreaded LIBSVM and XGBoost crashing](https://discourse.julialang.org/t/multithreaded-libsvm-and-xgboost-crashing/103179)

<div class="topic-metadata">

**Author:** [@dbass](https://discourse.julialang.org/u/dbass)\
**Replies:** 7\
**Last updated:** [August 25, 2023, 5:02pm UTC](https://discourse.julialang.org/t/multithreaded-libsvm-and-xgboost-crashing/103179 "2023-08-25T17:02:34Z")

</div>

Hello, I would like to perform crossvalidation and grid search using SVM (and XGBoost), using a parameter grid defined for each method. In MATLAB, within each split, I can run parfor, and each thread will train some mo…

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