### Use the Multithread Libraries

IBM C and C++ Compilers has two standard libraries that provide library functions for use in multithread programs.

The static library, CPPRMS36.LIB, is a statically linked multithread library, and CPPRMI36.LIB is an import multithread library, with the addresses of the functions contained in IBM C and C++ Compilers DLLs.

In addition to these two standard libraries, the IBM Open Class library is also available in multithread form. A single-thread version of this library is not provided.

Not all of the IBM C and C++ Compilers standard class libraries are available for multithread programs. The Complex Mathematics library is available for both single- and multithread programs. The single-thread version is CPPRSY36.LIB, and the multithread version is CPPRMY36.LIB. The C++ I/O Stream library is built into both the single-thread and the multithread run-time libraries. The IBM Open Class library also offers an IThread class that is an encapsulation of the Windows APIs for multithread programming.

The library ensures that only one thread at a time is active in the critical section of a function. Although this support is mandatory in a multithread program, it is unnecessary in a single-thread program. When you use the multithread libraries, you have more to consider than with the single-thread libraries. For example, because many library functions share data and other resources, the access to these resources must be serialized (limited to one thread at a time) to prevent functions from interfering with each other. Global variables and error handling are also affected by the multithread environment.

Compile and Link with Multithread Libraries
When you compile your multithread program, you must specify that you want to use the multithread libraries. Because threads share data, the operating system and library functions must ensure that only one thread is reading or writing data at one time. The multithread libraries provide this support. (You can use these libraries for single-thread programs, but the multithread support causes unnecessary overhead.)

To indicate that you want the multithread libraries, specify the /Gm compiler option.

If you intend to compile your source code into separate modules and then link them into one executable program file, you must build all modules using /Gm+ and ensure that the multithread libraries are used when you link them. Modules built with /Gm+ should not be mixed with modules built with /Gm-.

You can use either static linking (/Gd-) or dynamic linking (/Gd[+]) with multithread programs.

Debugging Threads
Multithreaded Applications
Run-Time Library Environments
Static and Dynamic Linking

Choose Runtime Libraries