Threads and Concurrent Programming

Silk Test Classic can run test cases in parallel on more than one machine. To run test cases in parallel, you can use parallel threads within main( ) or in a function called by main( ). If you attempt to run test cases in parallel on the same machine, you will generate a runtime error.

A more elegant alternative to parallel threads is to use a multitestcase function, which provides a robust multi-machine recovery system. For additional information on multitestcase code templates, see Using the Client/Server Template and Using the Parallel Template.

In the 4Test environment, a thread is a mechanism for interleaving the execution of blocks of client code assigned to different Agents so that one script can drive multiple client applications simultaneously. A thread is part of the script that starts it, not a separate script. Each thread has its own call stack and data stack. However, all the threads that a script spawns share access to the same global variables, function arguments, and data types. A file that one thread opens is accessible to any thread in that script.

While the creation of a thread carries no requirement that you use it to submit operations to a client application, the typical reason for creating a multithread script is so that each thread can drive test functions for one client, which allows multiple client application operations to execute in parallel.

When a script connects to a machine, any thread in that script is also connected to the machine. Therefore, you must direct the testing operations in a thread to a particular Agent machine. Threads interleave at the machine instruction level; therefore, no single 4Test statement is atomic with respect to a statement in another thread.