Skip to content

Tasks launched on foreign threads are getting stickied to them #47756

@vtjnash

Description

@vtjnash

We are probably noticing the absence of a threadpool here, and so making the new Task sticky, but there is the main task (1) which is also considered a background worker thread:

$ ./julia -t1 -q
julia> threadwork = @cfunction ()->(Threads.@spawn println(Threads.threadid(), " ", current_task().rngState0, " ", current_task().rngState1, " ", current_task().rngState2, " ", current_task().rngState3); Cint(0)) Cint ()
Ptr{Nothing} @0x000000010a7341f0

julia> tid = UInt[0]; @ccall pthread_create(tid::Ptr{UInt}, C_NULL::Ptr{Cvoid}, threadwork::Ptr{Cvoid}, C_NULL::Ptr{Cvoid})::Cint; @ccall pthread_join(tid[]::UInt, C_NULL::Ptr{Cvoid})::Cint
0

julia> Base.Workqueues
2-element Vector{Base.IntrusiveLinkedListSynchronized{Task}}:
 Base.IntrusiveLinkedListSynchronized{Task}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0))
 Base.IntrusiveLinkedListSynchronized{Task}(Base.IntrusiveLinkedList{Task}(Task (runnable) @0x0000000106fc8160, Task (runnable) @0x0000000106fc8160), Base.Threads.SpinLock(0))

This snippet works if we launch with -t2 or greater

Metadata

Metadata

Assignees

No one assigned

    Labels

    multithreadingBase.Threads and related functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions