diff options
author | Jonathan Nieder <jrn@google.com> | 2019-01-14 10:48:06 -0800 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2019-01-14 10:55:28 -0800 |
commit | 1131f35cd1904d42fe86222c46212a3fb89b5da8 (patch) | |
tree | 674d8b7601a8d03da023dafcf9d2d60623ba8510 /org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd | |
parent | 5f355ed4ad60118eb4331f0ea5b018d3fa16070b (diff) | |
download | jgit-1131f35cd1904d42fe86222c46212a3fb89b5da8.tar.gz jgit-1131f35cd1904d42fe86222c46212a3fb89b5da8.zip |
dfs: Remove synchronization in BlockBasedFile#LazyChannel
As explained in 'The "Double-Checked Locking is Broken"
Declaration'[*], Java's memory model does not support double-checked
locking:
class LazyReadableChannel {
private ReachableChannel rc = null;
public ReadableChannel get() {
if (rc == null) {
synchronized (this) {
if (rc == null) {
rc = new ReadableChannel();
}
}
}
return rc;
}
}
With JDK 5 and newer, there is a formal memory model that ensures this
works if "rc" is volatile, but it is still not thread-safe without
that.
Fortunately, this ReadableChannelSupplier is never passed between
threads, so it does not need to be thread-safe. Simplify by removing
the synchronization.
[*] https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
Change-Id: I0698ee6618d734fc129dd4f63fc047c1c17c94a9
Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd')
0 files changed, 0 insertions, 0 deletions