Skip to content

Commit

Permalink
add way to get index of thread in its threadpool
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Feb 3, 2025
1 parent 12698af commit 0012980
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions base/threadingconstructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ julia> Threads.threadid(Threads.@spawn "foo")
"""
threadid() = Int(ccall(:jl_threadid, Int16, ())+1)

"""
Threads.threadpool_threadidx() -> Int
Return the index of the current thread in its threadpool.
i.e. For the first default thread when 1 interactive thread exists this returns 1
because the interactive threadpool comes first in threadid order.
"""
function threadpool_threadidx()
pool = threadpool()
first_tid = first(threadpooltids(pool))
return Int(threadid() - first_tid + 1)
end

# lower bound on the largest threadid()
"""
Threads.maxthreadid() -> Int
Expand Down

0 comments on commit 0012980

Please sign in to comment.