Go to main content

Multithreaded Programming Guide

Exit Print View

Updated: November 2020
 
 

MT Interface Safety Levels

The man pages for functions and interfaces indicate how well the function or interface supports threads. The ATTRIBUTES section of each man page lists the MT-Level attribute, which is set to one of the safety level categories in the following list. These categories are explained more fully in the attributes(7) man page.

If a man page does not state explicitly that a function is MT-Safe, you must assume that the function is unsafe.

Safe

This code can be called from a multithreaded application

Safe with exceptions

See the NOTES sections of the man page for a description of the exceptions.

Unsafe

This interface is not safe to use with multithreaded applications unless the application arranges for only one thread at a time to execute within the library.

MT-Safe

This interface is fully prepared for multithreaded access. The interface is both safe and supports some concurrency.

MT-Safe with exceptions

See the NOTES sections of the man page for a description of the exceptions.

Async-Signal-Safe

This routine can safely be called from a signal handler. A thread that is executing an Async-Signal-Safe routine does not deadlock with itself when interrupted by a signal. See Async-Signal-Safe Functions in Oracle Solaris Threads

Fork1-Safe

This interface releases locks it has held whenever Oracle Solaris fork1(2) or POSIX fork(2) is called.

    Some functions have purposely not been made safe for the following reasons.

  • The interface made MT-Safe would have negatively affected the performance of single-threaded applications.

  • The library has an unsafe interface. For example, a function might return a pointer to a buffer in the stack. You can use re-entrant counterparts for some of these functions. The re-entrant function name is the original function name with "_r" appended.


Note - The only way to be certain that a function with a name not ending in "_r" is MT-Safe is to check the function's manual page. Use of a function identified as not MT-Safe must be protected by a synchronizing device or by restriction to the initial thread.

Reentrant Functions for Unsafe Interfaces

For most functions with unsafe interfaces, an MT-Safe version of the routine exists. The name of the MT-Safe routine is the name of the Unsafe routine with "_r" appended. For example, the MT-Safe version of asctime() is asctime_r(). The Oracle Solaris environment supplies the following "_r" routines: