How to increase the stack size of Julia threads?

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:

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

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

3 Likes