Lock Operation - Lock Step Configuration Dialog Box
- Aktualisiert2025-07-21
- 3 Minute(n) Lesezeit
Lock Operation - Lock Step Configuration Dialog Box
Lock Operation
To guarantee that only one thread executes certain steps at a time, insert a Lock step before the steps you want to protect and select Configure Lock from the context menu for the step. Select Lock from the Operation ring control in the Lock Step Configuration dialog box.
The Lock operation contains the following options:
- Lock Name or Reference Expression —The lock on which to perform the operation. You can specify the lock by name or by the object reference you receive when you create the lock using the Use Object Reference option in the Lock Reference Lifetime option. You can specify multiple locks using either a string array containing the names of the locks or an object reference array containing object references to the locks. When you specify multiple locks, the Lock operation attempts to lock all of the locks. If the operation cannot lock all of the locks, it unlocks the ones it has so far and tries again after a random delay. This continues until the operation either succeeds in locking all of the locks or the timeout you specify occurs. When you lock all of the locks a thread requires in a single Lock operation, you avoid the possibility of deadlock. However, when you lock more than one lock at a time, you lose the guarantee of first in first out (FIFO) ordering of which thread gets to lock a particular lock first.
- Create If Does Not Exist —Specifies whether the operation automatically creates the lock(s) you specify by name. Locks you create with this option have a reference lifetime of Same as Execution. Unlike the Create operation, you do not have the option of storing an object reference to the lock. The Lock Operation Lifetime you specify for this operation applies only to the length of time you acquire the lock, not the lifetime of the lock itself. The object you obtain with Use Object Reference is not the lock object itself, but instead it is an object that unlocks the lock when you destroy it. To obtain a reference to the Lock object itself or to choose a lifetime for the Lock object that is different from Same As Execution, you must use the Create operation.
-
Lock Operation Lifetime
—Specifies how long you want the thread to lock the lock. The attributes of this option are the same as those of
Synchronization object reference lifetimes
. Once the lifetime of the last Lock operation for the owning thread ends, the lock again becomes available for a thread to lock.
- Same as Sequence —Releases the object reference after the current sequence executes.
- Same as Thread —Releases the object reference after all sequences in the current thread execute.
- Use Object Reference —Use this option when you want to explicitly control the lifetime of the object reference or when you want to refer to the object using an object reference variable.
Note The Lock Reference Lifetime object you can acquire in the Create operation and the Lock Operation Lifetime object you can acquire here are two distinct objects and are not interchangeable. When using the Use Object Reference option for the Lock Operation Lifetime, do not use the same variable in which you store a reference to the Lock Reference Lifetime object. TestStand clears any variable you specify for the Use Object Reference option before storing the object that controls the Lock Operation Lifetime. Therefore, the reference to the Lock object is lost if you choose the variable that contains it as the variable to also contain the Lock Operation Lifetime object. - Timeout Enabled, Timeout Expression, Timeout Causes Run-Time Error —The timeout behavior when waiting to acquire the Lock. If a timeout occurs, the Step.Result.TimeoutOccurred property is set to True .