
- Allen Collins and Ronnie Van Zant
SyncLock
SyncLock Methods
| SyncLock() | Constructor for the SyncLock class |
| CheckAccess() | Checks to see if access is available |
| WaitForAccess() | Pauses the thread until access to the mutex/semaphore is obtained |
| ReleaseAccess() | Releases access to the mutex/semaphore |
Derived Classes
None
See Also
Class Hierarchy, SyncFlag, Thread
public method SyncLock(int MaxCount = 1,bool InitAccess = false)
Parameters
MaxCount
Value of maximum thread count which can gain access to the semaphore at one time. Should be >= 1, and 1 is default.
InitAccess
Gets access at creation time if true. False by default.
Return Value
None
Description
Constructor for the SyncLock class. If the MaxCount is 1, then the thread which gains access to the semaphore is guaranteed to be the only thread with access. It is therefore ideal for critical sections and protecting data modifications from getting corrupt.
SyncLock Class
public virtual method<bool> CheckAccess()
Parameters
None
Return Value
Returns true if access to the resource is currently available, and false if not.
Description
Checks the current availability of the semaphore. Note that due to the nature of multi-threaded programming, the successful return value of this method is no guarantee that a subsequent call to WaitForAccess() would gain immediate access. It is entirely possible that another thread sneaks in and gains access in the meantime.
SyncLock Class
public virtual method<bool> WaitForAccess(int TimeOut = 0)
Parameters
TimeOut
Value of timeout period in milliseconds. If access has not been obtained by that time, the call terminates. If the timeout period is set to zero, the timeout period is infinite.
Return Value
Returns true if access to the resource was obtained, and false if the call times out.
Description
Attempts to gain access to the sempahore. If the number of threads currently accessing the semaphore is equal to the MaxCount with which the semaphore was created, then the thread making this call will be queued up for access when it becomes available.
If the TimeOut value is greater than zero, then the call will terminate prematurely if access has not been granted after the time out value has been reached. If TimeOut is zero, the call will never time out.
SyncLock Class
public virtual method ReleaseAccess()
Parameters
None
Return Value
None
Description
Releases access from the semaphore, giving another queued thread a chance to gain access. This should only be called by a thread that has successfully obtained access to the thread in the first place.
SyncLock Class