Locking a Resource While Running Tests in Parallel in TestStand

Updated Feb 11, 2026

Reported In

Software

  • TestStand

Issue Details

I have a sequence file that is being called using the batch or parallel process model and it contains a step that uses a resource which cannot be accessed by two processes at once. How can I lock this resource so only one test socket can access it at a time but continue running my sequence with the batch or parallel model?

Solution

When running a sequence file using the Parallel or Batch process model, multiple test sockets may attempt to use the same hardware resource at the same time. If the resource only supports single‑client access — such as a power supply, communication bus, fixture mechanism, or shared instrument — you must prevent simultaneous use to avoid errors or undefined behavior.

 

TestStand offers three main ways to guarantee exclusive access:

 

 

All three options let you protect a critical section without disabling the Parallel or Batch execution flow.

 

 

Use Lock and Unlock Synchronization Steps (Most Explicit)

 

Insert a Lock step before the step that uses the exclusive resource, and an Unlock step immediately after it. All executions share the same lock name. When one socket acquires it, all other sockets wait until it is released.

lock steps in a sequence

 

Use Lock steps when:

  • You want full control and visibility of the synchronized region
  • The protected region spans multiple steps
  • You need to name and reuse the same lock from different sequences

 

Those steps are available in the Insertion Palette under the Synchronization group or in the shortcut (right-click) menus Insert Step » Synchronization » Lock and Insert Step » Synchronization » Unlock

 

For reference:

 

 

Use the Synchronization Panel in Step Settings

 

Instead of inserting separate Lock/Unlock steps, you can select the step that uses the resource and enable locking directly in its Synchronization panel. TestStand will automatically lock the resource before the step executes and release it once the step completes.

To configure it, go to the Step Settings pane, open the Properties tab and select the Synchronization category, as shown below.

setting a lock in the synchronization pane

 

Use the Lock setting in the Synchronization panel when:

  • Only one step in your sequence uses the resource.
  • You prefer cleaner sequences without extra steps.
  • You want automatic lock lifetime management.

 

For reference:

 

 

Using the Batch Model’s Built-in Batch Synchronization

 

If you are using the Batch process model, you have an additional synchronization tool:

 

Batch Synchronization Step Type

 

This step type allows you to control how test sockets enter a synchronized region. It can act as:

  • Serial (one socket at a time
  • One Thread Only (just the first socket executes while the others skip)
  • Parallel (all sockets must arrive and execute together) - This one won't help for the scope of this discussion.

 

The screenshot below shows the Batch Synchronization steps defining a section with Serial synchronization.

sequence with batch synchronization steps

 

Useful when coordinating actions such as:

  • Fixture loading/unloading
  • Mechanical operations
  • Limited-access shared instruments

 

For reference:

 

Batch Synchronization Options in the Synchronization Panel

 

When using the Batch model, the Synchronization Panel for each step includes Batch-specific options, such as:

  • Entry/exit behavior
  • Only one socket at a time” mode
  • All sockets must arrive before continuing” mode

 

synchronization pane

 

This is the simplest way to enforce mutual exclusion in batch systems without inserting additional steps.

 

For reference:

 

 

 

Choosing the Right Method

 

The table below lists different use cases and the recommended approach for each.

 

Use CaseRecommended Solution
Only one step uses the shared resourcePer-step Synchronization Panel
A section of multiple steps needs protectionLock/Unlock steps
Using Batch model and want socket-level coordinationBatch Synchronization
Want maximum clarity for future developersLock/Unlock steps

 

Additional Information

In addition to the primary synchronization methods described above (Lock/Unlock, per‑step synchronization settings, and Batch Synchronization), TestStand also provides other mechanisms that can be used to control access to shared resources in parallel executions. These options are less commonly used for straightforward mutual‑exclusion scenarios but may be valuable in more advanced or customized architectures. Two such alternatives are Semaphores and Auto Schedule Synchronization, which are outlined below for completeness.

 

 

Semaphores

 

TestStand semaphores can also be used to provide exclusive access to a resource by initializing them with a count of 1 (binary semaphore). This works similarly to a lock but is more flexible if you later want to allow limited parallelism (e.g., two sockets allowed instead of one).

 

Auto Schedule Synchronization

 

When using Parallel or Batch process model, TestStand can automatically control access to shared resources without requiring explicit Lock/Unlock steps. You simply assign steps to a scheduling resource, and the model ensures that only one test socket (or the allowed number) executes those steps at a time.

The following examples can help you better understand the concept of Auto Scheduling:

 

 

Note: Use this approach when the execution order of tests is not important. If your test requires the test results to be presented in a specific order, do not use auto scheduling.