Use the Multithread Libraries

The VisualAge C++ compiler has two standard libraries that provide library functions for use in multithread programs. The static library, CPPRMS40.LIB, is a statically linked multithread library, and CPPRMI40.LIB is an import multithread library, with the addresses of the functions contained in VisualAge C++ 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 VisualAge C++ standard class libraries are available for multithread programs. The Complex Mathematics library is available for both single- and multithread programs. The single-thread complex library is CPPRSY40.LIB, while the multithread version is CPPRMY40.LIB. The C++ I/O Stream library is built into both the VisualAge C++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.

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. Other functions can affect all threads running within a process. 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 linkwithmultithreadlib link 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 linkwithmultithreadlib(yes) and ensure that the multithread libraries are used when you link them. Modules built with linkwithmultithreadlib(yes) should not be mixed with modules built with linkwithmultithreadlib(no).

You can use either static linking (link(linkwithsharedlib,no)) or dynamic linking (link(linkwithsharedlib,yes)) with multithread programs.



Multithreaded Applications
Run-Time Library Environments

ngrelr.gif (548 bytes)
IThread