Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sleep causes Julia to hang in multi-threaded context #48430

Closed
bkamins opened this issue Jan 27, 2023 · 0 comments · Fixed by #48433
Closed

sleep causes Julia to hang in multi-threaded context #48430

bkamins opened this issue Jan 27, 2023 · 0 comments · Fixed by #48433
Labels
multithreading Base.Threads and related functionality

Comments

@bkamins
Copy link
Member

bkamins commented Jan 27, 2023

Reported and discussed in https://julialang.slack.com/archives/C688QKS7Q/p1674678148290409 (but probably it will be quickly lost so I am re-reporting it here as the issue persists and causes DataFrames.jl GitHub Actions CI to constantly fail).

On some systems (not all) when you start Julia with multiple threads and run the following code:

julia> for i in 1:10
           println("ping $i")
           @sync Threads.@spawn sleep(0.01)
           println("pong $i")
       end
ping 1
pong 1
ping 2
pong 2
ping 3
pong 3
ping 4
pong 4
ping 5
pong 5
ping 6
pong 6
ping 7
pong 7
ping 8
pong 8
ping 9
pong 9
ping 10
pong 10

julia> for i in 1:10
           @sync Threads.@spawn sleep(0.01)
       end

It freezes Julia. Note in particular, that doing some IO within the loop ensures that no freezing happens. (the same freezing happens if loop is replaced by multiple invocations of @sync Threads.@spawn sleep(0.01) in top level scope or if the loop is wrapped in a function and a function is called)

This problem is observed on Julia nightly on the following example configurations:

Julia Version 1.10.0-DEV.430
Commit 9b1ffbbe1b (2023-01-25 12:52 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 12 × Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 4 on 12 virtual cores

and

Julia Version 1.10.0-DEV.427
Commit dfab7be1f8b (2023-01-24 19:07 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 2 × Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, icelake-server)

and

Julia Version 1.10.0-DEV.430
Commit 9b1ffbbe1b (2023-01-25 12:52 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × 12th Gen Intel(R) Core(TM) i7-1260P
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, alderlake)
  Threads: 4 on 16 virtual cores

and

Julia Version 1.10.0-DEV.430
Commit 9b1ffbbe1bc (2023-01-25 12:52 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.3.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
  Threads: 4 on 4 virtual cores
vtjnash added a commit that referenced this issue Jan 27, 2023
When not in threaded region, only thread 0 will manage IO events, but it
may go to sleep if there are none started for it to watch.

Fix #48430
vtjnash added a commit that referenced this issue Jan 28, 2023
When not in threaded region, only thread 0 will manage IO events, but it
may have gone to sleep if there were no IO objects active for it to
watch earlier.

Fix #48430
@JeffBezanson JeffBezanson added the multithreading Base.Threads and related functionality label Jan 28, 2023
vtjnash added a commit that referenced this issue Jan 29, 2023
When not in threaded region, only thread 0 will manage IO events, but it
may have gone to sleep if there were no IO objects active for it to
watch earlier.

Fix #48430
KristofferC pushed a commit that referenced this issue Feb 1, 2023
When not in threaded region, only thread 0 will manage IO events, but it
may have gone to sleep if there were no IO objects active for it to
watch earlier.

Fix #48430

(cherry picked from commit 45b7e7a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multithreading Base.Threads and related functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants