# How to increase the stack size of Julia threads?

**URL:** <https://discourse.julialang.org/t/how-to-increase-the-stack-size-of-julia-threads/70359>\
**Category:** General Usage\
**Tags:** parallel, multithreading, stackoverflow\
**Created:** [October 25, 2021, 11:37pm UTC](https://discourse.julialang.org/t/how-to-increase-the-stack-size-of-julia-threads/70359 "2021-10-25T23:37:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [October 25, 2021, 11:37pm UTC](https://discourse.julialang.org/t/how-to-increase-the-stack-size-of-julia-threads/70359/1 "2021-10-25T23:37:23Z")

</div>

I’m doing multiple recursive computations ([Welzl’s algorithm](https://en.wikipedia.org/wiki/Smallest-circle_problem#Welzl%27s_algorithm)) in parallel using `Threads.@threads`, producing a stack overflow. This is on latest Linux and Julia 1.7.0-rc2.  
How do increase the size of a thread’s stack?

(It turns out that in this particular case the stack overflow is my fault and can’t be fixed by having larger stacks, but I’m still interested in how to change stack size.)

---

<div class="post-metadata">

**Author:** ![AntonReinhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antonreinhard/32/211306_2.png) [@AntonReinhard](https://discourse.julialang.org/u/AntonReinhard)\
**Post date:** [September 15, 2024, 11:43am UTC](https://discourse.julialang.org/t/how-to-increase-the-stack-size-of-julia-threads/70359/2 "2024-09-15T11:43:16Z")

</div>

I know this thread is old but I’ve found it multiple times now searching for the same answer, so here is what I did, in case it helps others who find this:

```Julia
with_stacksize(f, n) = fetch(schedule(Task(f, n)))
Threads.@threads for ...
    with_stacksize(8*1024*1024) do # execute with 8MiB stack size
        foo()
    end
end

```

I found it in [this github issue](https://github.com/EnzymeAD/Enzyme.jl/issues/1156)

It also looks like the default thread stack size will be increased in Julia 1.12: [Increase stack size limit to 8 MB? · Issue #54998 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/54998)

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [September 15, 2024, 12:15pm UTC](https://discourse.julialang.org/t/how-to-increase-the-stack-size-of-julia-threads/70359/3 "2024-09-15T12:15:28Z")

</div>

This is now also documented:

> <https://github.com/JuliaLang/julia/pull/55184>
>
> Fixes https://github.com/JuliaLang/julia/issues/55005 and helps work around issu…es discussed in https://github.com/JuliaLang/julia/issues/54998.
