EnterCriticalSection, ExitCriticalSection
EnterCriticalSection
EnterCriticalSection acquires the mutual-exclusion lock for a given object defined by the name of the critical section. You can release the lock by calling the ExitCriticalSection operation. Any other job is blocked from acquiring the lock until the lock is released. Action defines what to do in case of the block:
- Stop (without error) stops the job with status
stopped. - Stop with error stops the job with status
completedWithError. You can provide an error message that will appear in the Activity Log. - Wait makes the job waiting for the critical section to be unlocked and then entering it.
One of the use cases is to prevent concurrent execution of a scenario. To achieve this, put all operations of the scenario inside the Try block of the TryCatch operation and use EnterCriticalSection and ExitCriticalSection operations as shown in the following pseudocode. You want to check Skip catching in the Catch block not to ignore errors in the scenario operations.
TryCatch {
Try {
EnterCriticalSection: only_one_can_do_it_at_the_same_time
... Scenario operations go here ...
} Catch [Skip catching: checked] {
} Finally {
ExitCriticalSection: only_one_can_do_it_at_the_same_time
}
}ExitCriticalSection
ExitCriticalSection releases a lock acquired by the EnterCriticalSection operation.