gtpa2m2xApplication Programming

Threads

OSF DCE RPC is built on top of a thread model. In the TPF 4.1 system, the thread library name is CTHD and the library ordinal number is 0008.

The Thread Environment

To enable your TPF 4.1 system for threads, enter the ZCTKA ALTER command and specify the MTHD and TSTK parameters. The MTHD parameter specifies the maximum number of threads allowed in a process. The TSTK parameter specifies the maximum number of 4-KB ISO-C stack frames for each thread. The TSTK parameter must be a value from 4 to 1024 and must be a power of 2. See TPF Operations for more information on the ZCTKA ALTER command.

Thread Safety

Server applications run as threads and, therefore, must be thread safe. Most TPF services are currently thread safe; however, some services, such as file system and C function trace are not. Any function that causes the file system to be initialized, such as printf, and is used by a threaded application will cause results that cannot be predicted in the threaded application, such as depletion of 4-KB frames. C function trace is skipped in a threaded environment. The TPF recommendation is for RPC server applications to exit the thread environment to run the call (see tpf_cresc in the TPF C/C++ Language Support User's Guide as one way to exit the thread environment), and then return to the thread environment when the call is completed. Parameters can still be passed back and forth using this method.

In addition to the server applications, the server itself runs as a thread. Typically, the server contains RPC run-time APIs and additional processing, such as initialization and cleanup. You must be certain that any additional processing that occurs in the server is thread safe.