Skip to content

Commit 0012980

Browse files
add way to get index of thread in its threadpool
1 parent 12698af commit 0012980

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

base/threadingconstructs.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ julia> Threads.threadid(Threads.@spawn "foo")
3535
"""
3636
threadid() = Int(ccall(:jl_threadid, Int16, ())+1)
3737

38+
"""
39+
Threads.threadpool_threadidx() -> Int
40+
41+
Return the index of the current thread in its threadpool.
42+
i.e. For the first default thread when 1 interactive thread exists this returns 1
43+
because the interactive threadpool comes first in threadid order.
44+
"""
45+
function threadpool_threadidx()
46+
pool = threadpool()
47+
first_tid = first(threadpooltids(pool))
48+
return Int(threadid() - first_tid + 1)
49+
end
50+
3851
# lower bound on the largest threadid()
3952
"""
4053
Threads.maxthreadid() -> Int

0 commit comments

Comments
 (0)