-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use Threads.Condition for package locks #41366
Conversation
lock(loading) do | ||
wait(loading) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lock/wait code pattern is always wrong (it is why it forces you to write this out), since it is failing to protect the data. You'll need to rewrite much more of this code to be thread-safe and data-race-free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on that? The usage pattern of Threads.Condition is something that is sparsely documented https://docs.julialang.org/en/v1/base/multi-threading/#Synchronization, so if this is "always" wrong it would be great if you could improve the documentation.
Is your point that I might be woken to soon and I need to ensure that the condition I am waiting for has actually been met?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you take a lock, you need to ensure it contains all of the shared data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could use a lock for all the global package state, which can be shared by all the per-package Conditions?
Since this is marked as a "bugfix". What is the bug here, how can it be triggered? Anything that has changed here compared to earlier Julia versions? |
It's not a regression, but package loading/require is not threadsafe. I can try coming up with a MWE, but the error above stems from a parallel test runner used at RelationalAI. |
I wont have time to work on this, but I created a reproducer independent of Distributed.jl #41546 |
@Sacha0 reported a concurrency violation in this code.
This was on #38405, but I suspect with enough creativity one could come up with a pure Threads.@Spawn example.
@Sacha0 can I punt thinking about a test to you?