@@ -5,11 +5,13 @@ of Julia multi-threading features.
5
5
6
6
## Starting Julia with multiple threads
7
7
8
- By default, Julia starts up with a single thread of execution. This can be verified by using the
9
- command [ ` Threads.nthreads() ` ] ( @ref ) :
8
+ By default, Julia starts up with 2 threads of execution; 1 worker thread and 1 interactive thread.
9
+ This can be verified by using the command [ ` Threads.nthreads() ` ] ( @ref ) :
10
10
11
11
``` jldoctest
12
- julia> Threads.nthreads()
12
+ julia> Threads.nthreads(:default)
13
+ 1
14
+ julia> Threads.nthreads(:interactive)
13
15
1
14
16
```
15
17
@@ -22,13 +24,20 @@ The number of threads can either be specified as an integer (`--threads=4`) or a
22
24
(` --threads=auto ` ), where ` auto ` tries to infer a useful default number of threads to use
23
25
(see [ Command-line Options] (@ref command-line-interface) for more details).
24
26
27
+ See [ threadpools] (@ref man-threadpools) for how to control how many ` :default ` and ` :interactive ` threads are in
28
+ each threadpool.
29
+
25
30
!!! compat "Julia 1.5"
26
31
The ` -t ` /` --threads ` command line argument requires at least Julia 1.5.
27
32
In older versions you must use the environment variable instead.
28
33
29
34
!!! compat "Julia 1.7"
30
35
Using ` auto ` as value of the environment variable [ ` JULIA_NUM_THREADS ` ] (@ref JULIA_NUM_THREADS) requires at least Julia 1.7.
31
36
In older versions, this value is ignored.
37
+
38
+ !!! compat "Julia 1.12"
39
+ Starting by default with 1 interactive thread, as well as the 1 worker thread, was made as such in Julia 1.12
40
+
32
41
Lets start Julia with 4 threads:
33
42
34
43
``` bash
@@ -96,10 +105,17 @@ using Base.Threads
96
105
Interactive tasks should avoid performing high latency operations, and if they
97
106
are long duration tasks, should yield frequently.
98
107
99
- Julia may be started with one or more threads reserved to run interactive tasks:
108
+ By default Julia starts with one interactive thread reserved to run interactive tasks, but that number can
109
+ be controlled with:
100
110
101
111
``` bash
102
112
$ julia --threads 3,1
113
+ julia> Threads.nthreads(:interactive)
114
+ 1
115
+
116
+ $ julia --threads 3,0
117
+ julia> Threads.nthreads(:interactive)
118
+ 0
103
119
```
104
120
105
121
The environment variable [ ` JULIA_NUM_THREADS ` ] (@ref JULIA_NUM_THREADS) can also be used similarly:
0 commit comments