> My answer to that is in general, no. Because '...' can include arbitrary side-effect inducing statements that can't be moved around without affecting the behavior. As the poster discovered.
Sorry, I meant to write: synchronized(this) { a = AcquireLock(); for(c = 0; c < 100; c++) { f(); } } ReleaseLock(a); which is inline with what the blog post was proposing. To repeat the blog is a question: for (...) {…
>Just looking at your final example, I can't understand how you can say that is unsafe Let me change the example a bit. Say we have two locks aL and bL, that we must always acquire in the order aL first and then bL.…
>And it's unsafe? For what definition of safety? Let me try to answer with an example. Let us say, we have original code like this: synchronized(this) { a(); b(); } c(); synchronized(this) { d(); e(); } It would be…
Regarding the question in the 1st topic: (https://shipilev.net/jvm-anatomy-park/1-lock-coarsening-for-...) " for (...) { synchronized (obj) { // something } } …could it optimize into this? synchronized (this) { for…
> My answer to that is in general, no. Because '...' can include arbitrary side-effect inducing statements that can't be moved around without affecting the behavior. As the poster discovered.
Sorry, I meant to write: synchronized(this) { a = AcquireLock(); for(c = 0; c < 100; c++) { f(); } } ReleaseLock(a); which is inline with what the blog post was proposing. To repeat the blog is a question: for (...) {…
>Just looking at your final example, I can't understand how you can say that is unsafe Let me change the example a bit. Say we have two locks aL and bL, that we must always acquire in the order aL first and then bL.…
>And it's unsafe? For what definition of safety? Let me try to answer with an example. Let us say, we have original code like this: synchronized(this) { a(); b(); } c(); synchronized(this) { d(); e(); } It would be…
Regarding the question in the 1st topic: (https://shipilev.net/jvm-anatomy-park/1-lock-coarsening-for-...) " for (...) { synchronized (obj) { // something } } …could it optimize into this? synchronized (this) { for…