Defines a reader/writer lock that used to control exclusive tree access when needed. The public methods for EnableCount(), Clear(), and UnloadCache() each acquire an exclusive (write) lock while all other public methods acquire a shared (read) lock. By default this lock is non-operational (an instance of IgnoreLocking) so if you need the above methods to work while multiple threads are accessing the tree, or if you exclusive access to the tree, specify a lock instance. Since this lock is primarily a read-heavy lock consider using the ReaderWriterLocking or SimpleReadWriteLocking.
Syntax
Visual Basic (Declaration) | |
---|
Public Overridable Property CallLevelLock As ILockStrategy |
Example
BPlusTree/BPlusTree.Test/ThreadedBTreeTest.cs
C# | Copy Code |
---|
BPlusTree<KeyInfo, DataValue>.OptionsV2 options = new BPlusTree<KeyInfo, DataValue>.OptionsV2(
new KeyInfoSerializer(), new DataValueSerializer(), new KeyInfoComparer());
const int keysize = 16 + 4;
const int valuesize = keysize + 256 + 44;
options.CalcBTreeOrder(keysize, valuesize);
options.FileName = TempFile.TempPath;
options.CreateFile = CreatePolicy.Always;
options.FileBlockSize = 8192;
options.StorageType = StorageType.Disk;
options.CacheKeepAliveTimeout = 10000;
options.CacheKeepAliveMinimumHistory = 0;
options.CacheKeepAliveMaximumHistory = 200;
options.CallLevelLock = new ReaderWriterLocking();
options.LockingFactory = new LockFactory<SimpleReadWriteLocking>();
options.LockTimeout = 10000;
using(BPlusTree<KeyInfo, DataValue> dictionary = new BPlusTree<KeyInfo, DataValue>(options))
using(WorkQueue work = new WorkQueue(Environment.ProcessorCount))
{
Exception lastError = null;
work.OnError += delegate(object o, ErrorEventArgs e) { lastError = e.GetException(); };
for (int i = 0; i < Environment.ProcessorCount; i++)
work.Enqueue(new ThreadedTest(dictionary, 1000).Run);
Assert.IsTrue(work.Complete(true, 60000));
Assert.IsNull(lastError, "Exception raised in worker: {0}", lastError);
} |
VB.NET | Copy Code |
---|
Dim options As New BPlusTree(Of KeyInfo, DataValue).OptionsV2(New KeyInfoSerializer(), New DataValueSerializer(), New KeyInfoComparer())
Const keysize As Integer = 16 + 4
Const valuesize As Integer = keysize + 256 + 44
options.CalcBTreeOrder(keysize, valuesize)
options.FileName = TempFile.TempPath
options.CreateFile = CreatePolicy.Always
options.FileBlockSize = 8192
options.StorageType = StorageType.Disk
options.CacheKeepAliveTimeout = 10000
options.CacheKeepAliveMinimumHistory = 0
options.CacheKeepAliveMaximumHistory = 200
options.CallLevelLock = New ReaderWriterLocking()
options.LockingFactory = New LockFactory(Of SimpleReadWriteLocking)()
options.LockTimeout = 10000
Using dictionary As New BPlusTree(Of KeyInfo, DataValue)(options)
Using work As New WorkQueue(Environment.ProcessorCount)
Dim lastError As Exception = Nothing
work.OnError += Function(o As Object, e As ErrorEventArgs) Do
lastError = e.GetException()
End Function
Dim i As Integer = 0
While i < Environment.ProcessorCount
work.Enqueue(New ThreadedTest(dictionary, 1000).Run)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Assert.IsTrue(work.Complete(True, 60000))
Assert.IsNull(lastError, "Exception raised in worker: {0}", lastError)
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also