Thread Safe Usage

The IMSL C Math Library is thread safe based on OpenMP. That means it can be safely called from a multithreaded application if the calling program adheres to a few important guidelines. In particular, IMSL C Math Library’s implementation of error handling and I/O must be understood.

Error Handling

C Math Library’s error handling in a multithreaded application behaves similarly to how it behaves in a single-threaded application. The major difference is that an error stack exists for each thread calling C Math Library functions. The result of separate error stacks for each thread is greater control of the error handler options for each thread. Each thread can set its own options for the C Math Library error handler using imsl_error_options_none. For an example of setting error handler options for separate threads, see Chapter 12, Utilities, Example 3 of imsl_error_options_none.

Routines that Produce Output

A number of routines in C Math Library can be used to produce output. The function imsl_output_file_none can be used to control the file to which the output is directed. In an application with a single thread of execution, a single call to imsl_output_file_none can be used to set the file to which the output will be directed. In a multithreaded application each thread must call imsl_output_file_none to change the default setting of where output will be directed. See the Utilities chapter, Example 2 of imsl_output_file_none for more details.