Skip to content

If the user explicitly asked for 1 thread don't add an interactive one. #57454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 4, 2025
Merged
7 changes: 4 additions & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ Language changes
* Julia now defaults to 1 "interactive" thread, in addition to the 1 default "worker" thread. i.e. `-t1,1`.
This means in default configuration the main task and repl (when in interactive mode), which both run on
thread 1, now run within the `interactive` threadpool. The libuv IO loop also runs on thread 1,
helping efficient utilization of the worker threadpool used by `Threads.@spawn`. Pass `0` to disable the
interactive thread i.e. `-t1,0` or `JULIA_NUM_THREADS=1,0`, or `-tauto,0` etc. The zero is explicitly
required to disable it, `-t2` will set the equivalent of `-t2,1` ([#57087]).
helping efficient utilization of the worker threadpool used by `Threads.@spawn`. Asking for specifically 1 thread
(`-t1`/`JULIA_NUM_THREADS=1`) or passing `0` will disable the interactive thread i.e. `-t1,0` or `JULIA_NUM_THREADS=1,0`
, or `-tauto,0` etc. Asking for more than 1 thread will enable the interactive thread so
`-t2` will set the equivalent of `-t2,1` ([#57087]).
* When a method is replaced with an exactly equivalent one, the old method is not deleted. Instead, the
new method takes priority and becomes more specific than the old method. Thus if the new method is deleted
later, the old method will resume operating. This can be useful in mocking frameworks (as in SparseArrays,
Expand Down
3 changes: 3 additions & 0 deletions doc/src/manual/multi-threading.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ each threadpool.

!!! compat "Julia 1.12"
Starting by default with 1 interactive thread, as well as the 1 worker thread, was made as such in Julia 1.12
If the number of threads is set to 1 by either doing `-t1` or `JULIA_NUM_THREADS=1` an interactive thread will not be spawned.

Lets start Julia with 4 threads:

Expand Down Expand Up @@ -144,6 +145,8 @@ julia> nthreads(:interactive)
julia> nthreads()
3
```
!!! note
Explicitly asking for 1 thread by doing `-t1` or `JULIA_NUM_THREADS=1` does not add an interactive thread.

!!! note
The zero-argument version of `nthreads` returns the number of threads
Expand Down
3 changes: 3 additions & 0 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@
if (nthreadsi == 0)
jl_options.nthreadpools = 1;
}
} else if (nthreads == 1) { // User asked for 1 thread so don't add an interactive one

Check warning on line 663 in src/jloptions.c

View workflow job for this annotation

GitHub Actions / Check whitespace

Whitespace check

trailing whitespace
jl_options.nthreadpools = 1;
nthreadsi = 0;
}
jl_options.nthreads = nthreads + nthreadsi;
}
Expand Down
2 changes: 2 additions & 0 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ void jl_init_threading(void)
if (errno != 0 || endptr == cp || nthreads <= 0)
nthreads = 1;
cp = endptr;
if (nthreads == 1) // User asked for 1 thread so lets assume they dont want an interactive thread
nthreadsi = 0;
}
if (*cp == ',') {
cp++;
Expand Down
Loading