Skip to main content

Lock

Obtains a logical lock on a variable name.

Synopsis

Lock(varname[,timeout])

Arguments

varname Name of the variable to be locked.
timeout Optional — A numeric expression indicating the number of seconds to wait to obtain the lock.

Description

Returns true if the lock was obtained, false otherwise.

Each time a lock is obtained on a varname a lock count is incremented for this varname. Unlock decrements this count. Only when the lock count falls to zero will the logical lock be released. For this reason, you should balance each call to Lock with a corresponding call to Unlock.

If a timeout is not specified, Lock will wait indefinitely for the lock to be obtained. Specifying a timeout causes the lock attempt to wait up to the timeout number of seconds to obtain the lock.

Example

The following example uses the Lock function to obtain a logical lock on a varname with a timeout of 10 seconds.

If Lock(^PatientData(PatientID), 10) = True Then
  Println "Got the Lock"
  Unlock(^PatientData(PatientID))
Else
  Println "Couldn't get the lock"
End If

See Also

FeedbackOpens in a new tab