Introduction > Thread Safe Usage

Thread Safe Usage

The IMSL C Stat Library is thread safe. 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 Stat Library’s implementation of signal handling, error handling, and I/O must be understood.

Initialization

Initialization is required for certain Windows applications. Refer to function imsls_initialize, Chapter 15, “Utilities”, for information on when this is required and for examples.

Signal Handling

When calling C Stat Library from a multithreaded application it is necessary to turn
C Stat Library’s signal-handling capability off.  The signal handling is off if the C Stat Library is OpenMP-enabled on the platform, otherwise, signal handling is turned off by making a single call to imsls_error_options before any calls are made to C Stat Library. For an example of turning off C Stat Library’s internal-signal handling, see Chapter 15, “Utilities”, Example 3 of imsls_error_options.

C Stat 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 Stat 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 Stat Library error handler using imsls_error_options.  For an example of setting error handler options for separate threads, see Chapter 15, “Utilities”,Example 3 of imsls_error_options.

Routines that Produce Output

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


RW_logo.jpg
Contact Support