Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

I'm ridin' my blues... away.

- Allen Collins and Ronnie Van Zant

 

aztec.system.SyncLock

public class SyncLock from<Base>

Base

SyncLock

The SyncLock class provides a general purpose semaphore to control access to resources across multiple threads. It can be used to control access to data and code sections. When a thread tries to gain access to the semaphore, the thread waits until it either gets access or times out (unless infinite timeout is specified).

 

The max semaphore count is specified in the constructor. If one, it behaves as mutex, allowing a single thread to access the resource at a time. This is useful for protecting one or more data items that need to be accessed or modified by a single thread at a time, and for creating "critical sections" in Aztec code. If the semapahore count is more than one, it allows controlled access of a specified maximum number of threads, forcing a thread to wait in a queue until another thread release access.

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

See Also

 


SyncLock()

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


CheckAccess()

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


WaitForAccess()

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


ReleaseAccess()

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

 

Copyright © 2010-2017

Aztec Development Group

All Rights Reserved

Download Aztec