In this section:
To enable testing multi-threaded applications, add the following option to Build Settings’ Compiler Options (described in Configuring Project and File Options):
This option will activate multi-thread support in the C++test's Runtime library, as well as disable use of Safe Stubs for thread-related routines.
- C++test's test executable must be linked with the appropriate runtime library (i.e. the multithreaded version of C Runtime Library for Visual C++ compilers or "pthread" library on UNIX).
- C++test's Runtime does not control threads’ life-time - we recommended you implement test cases so that all threads are terminated when the test case completes.
Known Problems and Limitations
Known problems and limitations:
- If multi-thread support is enabled (using -DCPPTEST_THREADS=1)—but no appropriate library is used during linking (or a multi- and single-threaded C Runtime is mixed)—then the test executable may produce corrupted test results, or may terminate unexpectedly.
- Unexpected behavior in a non-main thread (signal, unhandled exception, time-out) will cause the test executable to terminate.
Building the C++test Runtime Library
C++test's default Runtime Library has built-in support for testing multithreaded applications. No additional action is required unless you are building a custom runtime library with multithreaded support (e.g., for embedded testing). If you need to build a custom Runtime Library with the multi-thread support, add
"- DCPPTEST_THREADS_ENABLED=1" to the compiler command line.
Supported Thread APIs
The implementation of Runtime Library can use the following types of thread APIs:
- Windows Threads
- POSIX Threads
- VxWorks 6.x
Using Other Thread APIs
If you need to use another thread API (or a custom one), the following types and routines must be implemented.
Note that the CppTestThread.c file in the C++test Runtime sources contains definitions of thread support routines; it can be used as an example or as a base for changes.
TIs - Thread Local Storage
Note: C++test's Runtime assumes that a mutex can be statically initialized.