Skip to content

Commit

Permalink
Two simple examples for Threads (#49704)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt authored May 22, 2023
1 parent 3b84b08 commit 672f609
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions base/threadingconstructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ export threadid, nthreads, @threads, @spawn,
Get the ID number of the current thread of execution. The master thread has
ID `1`.
# Examples
```julia-repl
julia> Threads.threadid()
1
julia> Threads.@threads for i in 1:4
println(Threads.threadid())
end
4
2
5
4
```
"""
threadid() = Int(ccall(:jl_threadid, Int16, ())+1)

Expand Down Expand Up @@ -352,6 +366,17 @@ the variable's value in the current task.
!!! compat "Julia 1.9"
A threadpool may be specified as of Julia 1.9.
# Examples
```julia-repl
julia> t() = println("Hello from ", Threads.threadid());
julia> tasks = fetch.([Threads.@spawn t() for i in 1:4]);
Hello from 1
Hello from 1
Hello from 3
Hello from 4
```
"""
macro spawn(args...)
tp = :default
Expand Down

0 comments on commit 672f609

Please sign in to comment.