-
-
Notifications
You must be signed in to change notification settings - Fork 364
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
Synchronize evaluateGroupCached to avoid concurrent access to cache #2980
Conversation
def lock(key: K, onCollision: Option[() => Unit] = None): AutoCloseable = { | ||
lockKeys.synchronized { | ||
var shown = false | ||
while (!lockKeys.add(key)) { |
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.
Does this need to be a while
? I thought we're inside lockKeys.synchronized
, there should be no need to "try again" since nobody else else going to be able to mutate lockKeys
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 yes. At least, the Javadoc of the Object.wait
method suggests to do so:
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }
Using a file lock to allow mutex between different Mill processes would definitely also be nice. e.g. It's not uncommon for IntelliJ to be running a Mill process and for my shell to be running a Mill process. But intra-process mutex is already an improvement to the status quo so we can go ahead with this first |
I think providing a file-based lock strategy is the next logical step, but as it still needs to be performed on a task-granualarity, it might come with some performance implications. Maybe, we want it to be configurable. Or just use it, if we detect, that there is another Mill running. |
With this change, we synchronize evaluations of the same terminal task. This isn't necessarily needed for normal Mill executions, but in a BSP context, where multiple requests where handled concurrently in the same Mill instance, evaluating the same task concurrently can happen.
We don't synchronize multiple Mill-instances (e.g. run in two shells) or multiple evaluator-instances (which should have different
out
-dirs anyway).Fix: #2818
Pull request: #2980