Synchronization Step Types - Lock
- Updated2025-03-28
- 2 minute(s) read
Synchronization Step Types - Lock
Purpose
This example demonstrates how to use the Lock synchronization step to restrict execution flow in a sequence file that uses the Batch process model. When a lock is active, only one thread at a time can access the steps the lock contains.
Example File
Location
<TestStand Public>\Examples\Built-In Step Types\Synchronization Step Types\Synchronization Step Types - Lock.seq
Highlighted Features
- Batch process model
- Lock step type
Major API
None
Prerequisites
None
How to Use This Example
Complete the following steps to review the sequence functionality.
- Select Edit»Sequence File Properties to launch the Sequence File Properties dialog box. On the Advanced tab, the Model File control specifies the Batch process model, which will run the test sequence in multiple parallel executions (test sockets).
- On the Sequences pane, select the MainSequence.
- Review the steps in the MainSequence. The steps specify the following behaviors:
- The sequence uses Lock steps to ensure that only one test socket is executing the single-threaded steps at a given time, which is useful in cases where the step requires a shared resource, such as an instrument, that only one step at a time can use.
- In section one, the sequence first creates and then performs the lock operation in the Create and Lock "Lock 1" step. Once one test socket calls the Lock "Lock 1" step, all other test sockets wait at the step until the original socket releases the lock in the Unlock "Lock 1" step.
- In section three, for the Single-threaded Test 5 step, notice that the Synchronization panel of the Properties tab of the Step Settings pane contains a Use Lock to Allow Only One Thread at a Time to Execute the Step option, which is enabled. This option applies a lock for the step without the need for lock steps.
- In section four, the Create Lock step stores the lock reference in a local variable. The lock operation uses this variable to identify the lock, and stores a reference to the lock operation in a second variable.
Complete the following steps to run this example.
- Select the Execute menu and confirm that a checkmark appears next to the Tracing Enabled option.
- Select Execute»Single Pass to run the sequence. TestStand creates three test sockets, and each test socket executes the MainSequence. The multi-threaded steps execute simultaneously across all test sockets. Observe that the locked code runs only on a single socket at any given time.