Know what you are importing and whether it is safe.
A threaded program cannot arbitrarily enter nonthreaded code.
Threaded code can safely refer to unsafe code only from the initial thread.
This ensures that the static storage associated with the initial thread is used only by that thread.
Sun-supplied libraries are defined to be safe unless explicitly documented as unsafe.
If a reference manual entry does not say whether a function is MT-Safe, it is safe. All MT-unsafe functions are identified explicitly in the manual page.
Use compilation flags to manage binary incompatible source changes. (See Chapter 7, Compiling and Debugging"for complete instructions.)
-D_REENTRANT enables multithreading with the Solaris threads -lthread library
-D_POSIX_C_SOURCE with -lpthread gives POSIX threads behavior
-D_POSIX_PTHREADS_SEMANTICS with -lthread gives both Solaris threads and pthreads interfaces with a preference given to the POSIX interfaces when the two interfaces conflict.
When making a library safe for multithreaded use, do not thread global process operations.
Do not change global operations (or actions with global side effects) to behave in a threaded manner. For example, if file I/O is changed to per-thread operation, threads cannot cooperate in accessing files.
For thread-specific behavior, or thread cognizant behavior, use thread facilities. For example, when the termination of main() should terminate only the thread that is exiting main(), the end of main() should be:
thr_exit(); /*NOTREACHED*/