by chrisseaton · 8y ago · 0 comments
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 (...) {
synchronized (obj) {
// something
}
}
…could it optimize into this? synchronized (this) {
for (...) {
// something
}
}
My answer to that is in general, no.Yes, but I think it's an assumption so obvious as to be not worth stating that the author means as long as ... does not do that.
Because '...' can include arbitrary side-effect inducing statements that can't be moved around without affecting the behavior. As the poster discovered.