-
Notifications
You must be signed in to change notification settings - Fork 1.1k
lazy val locking #2275
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
Comments
Hi Andrzej, Thanks for writing. You are right that the implementation has a formal bug. Strange that we haven't seen it ever occur in hours and hours of benchmarking the implementation both done by me and Alex. Unfortunately your fix is both inefficient and incorrect:
Could you please come to #2276 and review my proposed fix? Thank you, |
// I've modified your comment to fix github formatting. |
What is the status of this fix? |
I think I just hit this for the first time, I was running our test suite but it got stuck at the very first test in |
Just hit this again in |
It seems I can reliably reproduce the issue with the following program: object Test {
var count = 0
@volatile lazy val x: Int = {
if (count < 100) {
count += 1
???
}
1
}
def main(args: Array[String]): Unit = {
def fetchLazy(): Unit = try x catch { case _: Throwable => fetchLazy() }
for (_ <- 0 until 10) {
new Thread(() => fetchLazy()).start()
}
}
} |
Since we have concerns about the size of the generated code and the correctness of the new implementation, I propose we revert to the Scala 2 implementation for thread safe lazy fields. One can always revive SIP-20 in the future. |
I wrote a comment on SIP-20. And I think problem is also with dotty because it is based on same concept.
I found a problem with implementation of lazy val. When one thread will initialize lazy val and other check that val is already initializing then call wait4Notification and set flag to 2. Then it is possibility that first thread finished initializing and checked that flag which is set to 2 and do notifyAll on monitor. After that second thread will call wait and it will lock forever. Problem is with time between setting flag and wait on monitor.
My solution is :
The text was updated successfully, but these errors were encountered: