DCE Application Programming Guide
Application Programming With NonStop DCE
Threads
HP NonStop DCE Application Programming Guide—429551-003
3-5
Using Standard Libraries
Using Standard Libraries
These subsections discuss the use of standard libraries:
•
No Need for Jackets on page 3-5
•
No Asynchronous Cancels on page 3-5
•
Using Standard Libraries With Static Data on page 3-5
No Need for Jackets
With NonStop DCE, threads execute until they relinquish control. A thread can never
be preempted while executing code in a standard library. Therefore, you do not need to
protect standard libraries with global mutexes or use special header files. With
NonStop DCE, standard libraries do not require jackets or other modifications to make
them thread-safe or reentrant.
No Asynchronous Cancels
NonStop DCE does not support the asynchronous receipt of cancels; a thread can
never exit prematurely from a standard library because of cancellation. Therefore, you
do not need to protect the run-time state of standard libraries by disabling cancelability
before making a call into the library.
Using Standard Libraries With Static Data
Be especially careful when using standard libraries that maintain global or static data.
Although standard libraries are inherently thread-safe when used with NonStop DCE,
the uncontrolled use of the TNS shared run-time library by multiple threads can have
these complications:
•
Pointers to library data
Some libraries contain functions that return pointers to static data. If you are not
careful, one thread can invalidate another thread’s pointer. For example, the
getpwuid() function returns a pointer to data about a user. This data is stored in
a static variable in the library that is overlaid on the next call to this function by any
thread.
The safest way to use functions that return pointers to static library data is to
immediately copy the data to thread-private memory.
•
Libraries that maintain context across calls
Some libraries maintain context across calls. Be careful to avoid interaction
between threads.
As an example, consider the setpwent() and getpwent() functions. The
getpwent() function returns information about the next user in the user
database, with the current position kept implicitly in the library. The setpwent()
function ensures that the next call to getpwent() returns the first user entry. A