Skip to content

Deadlock from simple repeated @spawn and wait #36699

@tkf

Description

@tkf

Simply repeating @spawn and wait causes a dead lock:

julia> for _ in 1:1000
           for _ in 1:1000
               ts = [(Threads.@spawn nothing) for _ in 1:Threads.nthreads()]
               foreach(wait, ts)
           end
           print('.')
           flush(stdout)
       end
............................................^CERROR: InterruptException:
Stacktrace:
 [1] poptask(W::Base.InvasiveLinkedListSynchronized{Task})
   @ Base ./task.jl:706
 [2] wait
   @ ./task.jl:714 [inlined]
 [3] wait(c::Base.GenericCondition{Base.Threads.SpinLock})
   @ Base ./condition.jl:106
 [4] _wait(t::Task)
   @ Base ./task.jl:240
 [5] wait
   @ ./task.jl:267 [inlined]
 [6] foreach(f::typeof(wait), itr::Vector{Task})
   @ Base ./abstractarray.jl:2072
 [7] top-level scope
   @ REPL[4]:4

To edit a specific method, type the corresponding number into the REPL and press Ctrl+Q

julia> versioninfo()
Julia Version 1.6.0-DEV.477
Commit b07594dac0 (2020-07-16 18:42 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

julia> Threads.nthreads()
4

In the above session, I saw '.'s printed pretty rapidly until it hangs. Then I terminated the evaluation with Ctrl-C.

I see this in 1.5.0-rc1.0 but not in 1.4.

(I tried JULIA_RR_RECORD_ARGS='--chaos --num-cores=4' JULIA_NUM_THREADS=4 julia --startup-file=no --bug-report=rr etc. to get a deadlock in rr. But so far I couldn't get it under rr.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    multithreadingBase.Threads and related functionalityregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions