Ext.AcquireLock()

(SBM On-Premise/PaaS only) A mutex-locking function called by a concurrent script when it needs to use a shared resource that should only be accessed by one script at a time.

Function Signature

 bool Ext.AcquireLock( [msTimeout] )

Parameters

Parameter Type Description

msTimeout

int

Optional. The number of milliseconds to wait for the lock to be available. Defaults to an infinite wait.

While the script is waiting, its execution is frozen. This may cause performance problems for long scripts or scripts that occur repeatedly. The wait occurs until other scripts have released the lock.

All scripts share the same mutex.

Return

Type Description

bool

Returns true if a lock was acquired successfully. Returns false if the time-out period passed. If false, the script should not execute sensitive operations because another concurrent script has the lock.

Technical Details

SBM ModScript version: 11.3.

Notes

For example, if a script needs to read a serial number from a file, increment the number, and write it back, the script should call this function before accessing the file. When the script is done with the serial number file, it should call Ext.ReleaseLock() to allow other scripts access once again. If all scripts using this file call these locking functions before and after use, then the file is never accessed by more than one script at a time. In this example, the serial numbers read and written by concurrent scripts are guaranteed valid for a single Web server configuration. Note that SBM automatically releases the lock when the script finishes execution. To determine if a lock is available, refer to Ext.LockIsAvailable().

Related Topics

Extension Functions