AshwiniRao avatar image
AshwiniRao asked ericnute edited

How to handle exit of multi-threads and still ensure continual of procedure execution

Hi team,


I am facing some problem while trying to exit from all thread execution.


The scenario is as mentioned below:

1. From the main procedure, start 4 different threads, each of which calls a different sub-procedure
2. While executing the procedure, if any one of the thread sets a particular variable to FAIL (FAIL cases), then we need to ABORT the execution of the other threads also and continue the execution of steps below.
3. After this step, there is a Waitthread step which waits until all the 4 threads complete.(which we reuqire in PASS case scenario)


I have handled the 'abort' from all threads by giving an 'exit' statement in the sub-procedure. (The behavior of exit command is to exit from the current procedure and exit all other threads and continue execution of the next step).


In the current scenario, I see that the procedure which we entered in each thread is being exit and also every thread exits if one of the procedures set the variable to FAIL. BUT, since, I have a waitthread statement (mandatorily required in PASS cases) in the main procedure; On Threadexit of such a waitthread statement, the main procedure also gets exit which is not as per the requirement.

I have tried changing the event "onThreadExit" to execute "continue" statement, but still it could not avoid exitting from the main procedure.

Can you please let me know an alternative way to handle exit from the sub-proc ensuring other threads exit, but we continue execution of the steps in the main procedure?


10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

AshwiniRao avatar image
AshwiniRao answered AshwiniRao posted

One more observation with respect to the above question:


I am seeing that the 'exit' command not only exits from the current procedure but also from the previously calling procedure, which is not the behavior as explained in iTest Help for this command, which states that:

"An exit step immediately stops executing the current procedure and all threads and continues execution after the step that called the procedure".


Is there any workaround to make it work the way we want as specified in the above question.


Please let me know. Thanks!

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

AdamB avatar image AdamB commented ·

Could you describe or attach your test case? 


Exit should definitely work as described in the help, so we should try to get to the bottom of what's going on here.

0 Likes 0 ·
AshwiniRao avatar image AshwiniRao AdamB commented ·



In the sample test-case attached, we are calling a sub-procedure from the main procedure and the subsequent step is a comment.


The sub-procedure definition consists of 2 threads starting simultaneously and executes a for loop. When the value of the variable in one of the for loops gets updated to a particular value, we are supposed to exit from both the threads and the sub- procedure and execute the remaining steps in the main proc. Hence, we have used the exit statement in the if condition.


But, we are seeing that on execution of EXIT command, the execution stops completely and hence, the comment step in the main procedure is not executed at all.

0 Likes 0 ·
KumarS avatar image KumarS AshwiniRao commented ·



iTest documentation is completely wrong on the description of "exit" action. Sorry for the hassle it might have caused.


"exit" action is going to "stop or terminate" execution completely. Think of it as "exit" from a shell or c program. The execution of exit kills the shell or program. The same is true for an iTest execution. "exit" will terminate execution.


In your example, I changed "exit" to "break" and that makes the thread break out of the loop and reach normal end. Note that one cannot use "return" action in this case because you have threads running in that procedure's context. I will file a bug to get the documentation fixed.

0 Likes 0 ·
AshwiniRao avatar image AshwiniRao KumarS commented ·

Hi Kumar,


So, does both 'exit' and 'ExitExecution' perform the same action? if so, what is the need to have 2 commands.

0 Likes 0 ·
RoyL avatar image RoyL AshwiniRao commented ·



I'm sorry that you had to live through this hassle.


To answer your question about the difference between 'exit' and 'ExitExecution': 


  • 'ExitExecution' is an action that is triggered by some 'Event' during execution (for example, a timeout -- the 'OnExecutionTimeout' event). Because a timeout can occur at any time, you do not want to place the action in a particular location in the test case -- instead,  iTest just 'listens' for the timeout event that triggers the action (exit execution and print out execution messages) if the specified timeout happens.


  • In contrast, 'exit' is an action that you can add as a test case step in a particular place (typically inside a loop that might go bad and you just want to exit the test case if that happens).


We have corrected the doc for the 'exit' action to:


An exit step immediately stops executing the current procedure and all threads to end test case execution.


The exit action does not change the existing execution result of the test case (Pass, Fail, Abort, or Indeterminate).


An appropriate execution message appears in the Execution view, in the Step Issues view, and in test reports.


The exit action has no configurable properties.

0 Likes 0 ·
JeffJ avatar image JeffJ ♦ RoyL commented ·

If I understand the original post, I think the solution that is needed is the ability to syncronize multiple threads.  With iTest 3.4.2, you'll need to create a global variable to inform your threads when other threads have completed.  I've taken the original post testcase and updated it to show how the two threads can "watch" each other and end if one or the other ends.  The parent can then tell what happened (based on checking the status for FAIL) and restart the threads is they were not successful.


Hopefully this will address the original post on how to handle multithread sync with iTest 3.4.2.

0 Likes 0 ·
AshwiniRao avatar image AshwiniRao JeffJ ♦ commented ·

Thanks! all for the response.

Jeff that helps. Thank you!

We have also used global variables to identify the threads are completed or not.




0 Likes 0 ·
KumarS avatar image KumarS AshwiniRao commented ·

We are adding more modern concepts of thread synchronization, events, semaphores in a future version of iTest. That will obviate the need for having global variables to maintain and manage thread states.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.