diff --git a/src/threading.c b/src/threading.c index 18c502cf94387a..962274401d57bf 100644 --- a/src/threading.c +++ b/src/threading.c @@ -709,6 +709,13 @@ void jl_init_threading(void) else { jl_n_markthreads = (nthreads / 2) - 1; } + // if `--gcthreads` or ENV[NUM_GCTHREADS_NAME] was not specified, + // cap the number of threads that may run the mark phase to + // the number of CPU cores + int cpu = jl_cpu_threads(); + if (jl_n_markthreads + 1 >= cpu) { + jl_n_markthreads = cpu - 1; + } } } int16_t ngcthreads = jl_n_markthreads + jl_n_sweepthreads;