diff --git a/src/threading.c b/src/threading.c index 8f8dd45c28507..a9384a76a2b01 100644 --- a/src/threading.c +++ b/src/threading.c @@ -392,12 +392,17 @@ void jl_init_threading(void) // how many threads available, usable jl_n_threads = JULIA_NUM_THREADS; - if (jl_options.nthreads < 0) // --threads=auto + if (jl_options.nthreads < 0) { // --threads=auto jl_n_threads = jl_cpu_threads(); - else if (jl_options.nthreads > 0) // --threads=N + } else if (jl_options.nthreads > 0) { // --threads=N jl_n_threads = jl_options.nthreads; - else if ((cp = getenv(NUM_THREADS_NAME))) - jl_n_threads = (uint64_t)strtol(cp, NULL, 10); + } else if ((cp = getenv(NUM_THREADS_NAME))) { + if (strcmp(cp, "auto")) { + jl_n_threads = (uint64_t)strtol(cp, NULL, 10); // ENV[NUM_THREADS_NAME] == "N" + } else { + jl_n_threads = jl_cpu_threads(); // ENV[NUM_THREADS_NAME] == "auto" + } + } if (jl_n_threads <= 0) jl_n_threads = 1; #ifndef __clang_analyzer__