Ensure safe publication of ChronicleMaps, created in ChronicleMapBuilder

This commit is contained in:
leventov
2016-10-01 22:09:54 +03:00
parent 1825fc61ee
commit 3b22bb5547
@@ -1501,6 +1501,8 @@ public final class ChronicleMapBuilder<K, V> implements
} finally {
if (result != null) {
result.registerRafReleaser();
// Ensure safe publication of a ChronicleMap
OS.memory().storeFence();
} else {
CanonicalRandomAccessFiles.release(file);
}
@@ -1664,6 +1666,8 @@ public final class ChronicleMapBuilder<K, V> implements
lazyNativeBytesStoreWithFixedCapacity(map.sizeInBytesWithoutTiers());
map.createMappedStoreAndSegments(bytesStore);
establishReplication(map);
// Ensure "safe publication" of a ChronicleMap
OS.memory().storeFence();
return map;
} catch (IOException e) {
// file-less version should never trigger an IOException.