Multithreaded Programming Guide

MT Interface Safety Levels

The man Pages(3): Library Routines use the following categories to describe how well an interface supports threads (these categories are explained more fully in the Intro(3) reference manual page).

Safe 

This code can be called from a multithreaded application.  

Safe with exceptions 

See the NOTES sections of these pages 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 in that it is both safe and it supports some concurrency.

MT-Safe with exceptions 

See the NOTES sections of these pages in the man Pages(3): Library Routines for a list 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 it is interrupted by a signal.  

Fork1-Safe 

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

See the table in Appendix C, MT Safety Levels: Library Interfaces,; for the safety levels of interfaces from the man Pages(3): Library Routines. Check the man page to be sure of the level.

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


Caution - Caution -

There is no way to be certain that a function whose name does not end in "_r" is MT-Safe other than by checking its reference 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 new MT-Safe routine is always the name of the old Unsafe routine with "_r" appended. The Table 6-1 "_r" routines are supplied in the Solaris system.

Table 6-1 Reentrant Functions

asctime_r(3c) 

gethostbyname_r(3n) 

getservbyname_r(3n) 

ctermid_r(3s) 

gethostent_r(3n) 

getservbyport_r(3n) 

ctime_r(3c) 

getlogin_r(3c) 

getservent_r(3n) 

fgetgrent_r(3c) 

getnetbyaddr_r(3n) 

getspent_r(3c) 

fgetpwent_r(3c) 

getnetbyname_r(3n) 

getspnam_r(3c) 

fgetspent_r(3c) 

getnetent_r(3n) 

gmtime_r(3c) 

gamma_r(3m)

getnetgrent_r(3n) 

lgamma_r(3m) 

getauclassent_r(3) 

getprotobyname_r(3n) 

localtime_r(3c) 

getauclassnam_r(3) 

getprotobynumber_r(3n) 

nis_sperror_r(3n) 

getauevent_r(3) 

getprotoent_r(3n) 

rand_r(3c) 

getauevnam_r(3) 

getpwent_r(3c) 

readdir_r(3c) 

getauevnum_r(3) 

getpwnam_r(3c) 

strtok_r(3c) 

getgrent_r(3c) 

getpwuid_r(3c) 

tmpnam_r(3s) 

getgrgid_r(3c) 

getrpcbyname_r(3n) 

ttyname_r(3c) 

getgrnam_r(3c) 

getrpcbynumber_r(3n) 

 

gethostbyaddr_r(3n) 

getrpcent_r(3n)