# Multi-Threading hangs in Windows

**URL:** <https://discourse.julialang.org/t/multi-threading-hangs-in-windows/101905>\
**Category:** General Usage\
**Tags:** multithreading\
**Created:** [July 21, 2023, 7:52pm UTC](https://discourse.julialang.org/t/multi-threading-hangs-in-windows/101905 "2023-07-21T19:52:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![schev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schev/32/51307_2.png) [@schev](https://discourse.julialang.org/u/schev)\
**Post date:** [July 21, 2023, 7:52pm UTC](https://discourse.julialang.org/t/multi-threading-hangs-in-windows/101905/1 "2023-07-21T19:52:43Z")

</div>

Hi Julia friends! I have a persistent problem with multi-threading hanging, sometimes for many minutes at a time. Notably, I only witness this when my code is allocating large amounts of memory. Of course, pre-allocating would generally solve the problem, but I can’t apply this solution in every case.

Here is a MWE, which is run on Julia 1.9.2 with 10 threads on a Windows machine (64-bit). The inner loop purposefully allocates a lot of memory in order to show the bug. When I run this code with @floop using only one or two threads (via the basesize trick), the problem goes away. It comes back as I use more threads.

```julia
using Plots

num_outer_loops = 1000
num_parallel_loops = 15
time_vec = zeros(num_outer_loops)
rvec1 = randn(10000)
rvec2 = randn(10000)
for ii in 1:num_outer_loops
    t1 = time()
    Threads.@threads for jj in 1:num_parallel_loops
        rvec_copy1 = rvec1.*rvec2
        rvec_copy2 = rvec1.*rvec2
        rvec_copy3 = rvec1.*rvec2
        rvec_copy4 = rvec1.*rvec2
        rvec_copy5 = rvec1.*rvec2
    end
    time_vec[ii] = time() - t1
    println(ii)
end

# plot hanging
Plots.plot(1:1000, time_vec, yaxis = :log, xlabel = "outer loop iteration", ylabel = "time (secs, log scale)")

```

Multi-threading hangs for ~3.3 seconds four times, which seems to be far longer than a simple gc routine:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/c/1c85902382b30f9103039f70914b1d0633300423.png)

Any suggestions @maleadt or @tkf or anyone else? Is this a bug?
