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 listed in Figure 16, Table 16, Interface Safety Levels. These categories are
explained more fully in the attributes(5) man page.
If a man page does not state explicitly that a function is MT-Safe,
you must assume that the function is unsafe.
Table 16 Interface Safety Levels
| |
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
|
|
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 Figure 17, Table 17, Reentrant Functions "_r" routines are supplied in the Oracle Solaris environment.
Table 17 Reentrant Functions
asctime_r(3c)
| gethostbyname_r(3nsl)
| getservbyname_r(3socket)
|
ctermid_r(3c)
| gethostent_r(3nsl)
| getservbyport_r(3socket)
|
ctime_r(3c)
| getlogin_r(3c)
| getservent_r(3socket)
|
fgetgrent_r(3c)
| getnetbyaddr_r(3socket)
| getspent_r(3c)
|
fgetpwent_r(3c)
| getnetbyname_r(3socket)
| getspnam_r(3c)
|
fgetspent_r(3c)
| getnetent_r(3socket)
| gmtime_r(3c)
|
gamma_r(3m)
| getnetgrent_r(3c)
| lgamma_r(3m)
|
getauclassent_r(3bsm)
| getprotobyname_r(3socket)
| localtime_r(3c)
|
getauclassnam_r(3bsm)
| getprotobynumber_r(3socket)
| nis_sperror_r(3nsl)
|
getauevent_r(3bsm)
| getprotoent_r(3socket)
| rand_r(3c)
|
getauevnam_r(3bsm)
| getpwent_r(3c)
| readdir_r(3c)
|
getauevnum_r(3bsm)
| getpwnam_r(3c)
| strtok_r(3c)
|
getgrent_r(3c)
| getpwuid_r(3c)
| tmpnam_r(3c)
|
getgrgid_r(3c)
| getrpcbyname_r(3nsl)
| ttyname_r(3c)
|
getgrnam_r(3c)
| getrpcbynumber_r(3nsl)
|
|
gethostbyaddr_r(3nsl)
| getrpcent_r(3nsl)
|
|
|