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
Function0 doesn't synchronize properly #9814
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9814?orig=1 |
@retronym said: A workaround is to restructure as: def apply(): Unit = {
val self = this
self.synchronized {
println("i'm synchronized!")
}
} The compiler looks for method bodies of the shape Fixing this will involve something like:
I'll flesh this out and submit a patch for 2.11.9 + 2.12.x in the next week. |
Moses Nakamura (mosesn) said: |
Moses Nakamura (mosesn) said: |
Moses Nakamura (mosesn) said: |
@retronym said: |
I found that scalac infers that synchronized entire an entire method's code means that the method should be synchronized. On Function0#apply, this means that it synchronizes the apply method. However, it doesn't synchronize Function0#apply$mcV$sp, presumably thinking that folks will not call that method directly. However, scalac compiles function invocations down to call that method directly.
This means that methods which are marked synchronized are not really synchronized.
javap -c Foo (edited for clarity)
javap -c Bar (edited for clarity)
The text was updated successfully, but these errors were encountered: