public readRegionAddrNonExcl ( long region_addr ) : IRegion | ||
region_addr | long | |
Résultat | IRegion |
public void T02_Region_References() { RegionExposedFiles rm = new RegionExposedFiles(InitMode.NEW_REGION, "C:\\BENDtst\\T01_Region_References"); byte[] data = { 1, 3, 4, 5, 6, 7, 8, 9, 10 }; bool delegate_called = false; { // put some data in the region IRegion region1 = rm.writeFreshRegionAddr(0, BLOCK_SIZE); { Stream output = region1.getNewAccessStream(); output.Write(data, 0, data.Length); output.Dispose(); } region1 = null; } System.GC.Collect(); { IRegion region2 = rm.readRegionAddrNonExcl(0); Stream rd1 = region2.getNewAccessStream(); rm.notifyRegionSafeToFree(0, delegate(long addr) { System.Console.WriteLine("** region safe to free delegate called"); delegate_called = true; }); rd1 = null; region2 = null; } rm = null; for (int x = 0; x < 1000; x++) { Thread.Sleep(5); System.GC.Collect(); if (delegate_called) { break; } } Assert.AreEqual(true, delegate_called, "region was never safe to free"); }
public void T05_Region_Concurrency() { RegionExposedFiles rm = new RegionExposedFiles(InitMode.NEW_REGION, "C:\\BENDtst\\T05_Region_Concurrency"); byte[] data = { 1, 3, 4, 5, 6, 7, 8, 9, 10 }; { // put some data in the region IRegion region1 = rm.writeFreshRegionAddr(0, BLOCK_SIZE); { Stream output = region1.getNewAccessStream(); output.Write(data, 0, data.Length); output.Close(); } } { IRegion region1 = rm.readRegionAddrNonExcl(0); Stream rd1 = region1.getNewAccessStream(); Stream rd2 = region1.getNewAccessStream(); // Assert.AreNotEqual(rd1, rd2, "streams should be separate"); for (int i = 0; i < data.Length; i++) { Assert.AreEqual(0, rd2.Position, "stream rd2 position should be indpendent"); Assert.AreEqual(i, rd1.Position, "stream rd1 position"); Assert.AreEqual(data[i], rd1.ReadByte(), "stream rd1 data correcness"); } } }