Struct ManyReadersOneWriterSynchronizer
This struct is for ADVANCED SYSTEM use-cases. DEVELOPERS: do not use this in a business application code. Represents an efficient SpinWait/Yield-based lock that allows many readers to operate concurrently and only one single concurrent writer. This struct must be used ONLY with a very fast/tight operations that do not block on IO and other locks, and are expected to complete under a tenth fraction of a second. Warning: this lock CAN NOT be held for longer than 5 hrs by design. DO NOT use this lock with IO-dependent operations. This is not really a limitation as this class is used to guard operations which are very fast (fractions of a second) and should fail faster otherwise. This lock IS NOT REENTRANT!
Inherited Members
Namespace: Azos.Platform
Assembly: Azos.dll
Syntax
public struct ManyReadersOneWriterSynchronizer
Methods
GetReadLock(Func<Object, Boolean>, Object)
Obtains a read lock returning true on success. Many threads may obtain a read lock at the same time, however a single write lock excludes any read locks, corollary any single read lock held excludes anyone obtaining a write lock. False is returned if cancel func was supplied and returned true to cancel-out the waiting
Declaration
public bool GetReadLock(Func<object, bool> cancel = null, object cancelContext = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Object, System.Boolean> | cancel | |
System.Object | cancelContext |
Returns
Type | Description |
---|---|
System.Boolean |
GetWriteLock(Func<Object, Boolean>, Object)
Obtains a write lock returning true on success. Only one thread may hold a write lock at a time, and noone else can obtain a read lock until the write lock is released. False is returned if cancel func was supplied and returned true to cancel-out the waiting
Declaration
public bool GetWriteLock(Func<object, bool> cancel = null, object cancelContext = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Object, System.Boolean> | cancel | |
System.Object | cancelContext |
Returns
Type | Description |
---|---|
System.Boolean |
ReleaseReadLock()
Releases the read lock that was previously obtained by a call to GetReadLock()
Declaration
public void ReleaseReadLock()
ReleaseWriteLock()
Releases the write lock that was previously obtained by a call to GetWriteLock()
Declaration
public void ReleaseWriteLock()
TryGetWriteLock()
Tries to obtain the write lock returning true on success, false if lock could not be taken - either someone reads or writes. Only one thread may hold a write lock at a time
Declaration
public bool TryGetWriteLock()
Returns
Type | Description |
---|---|
System.Boolean |