JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Multithreaded Programming Guide     Oracle Solaris 11.1 Information Library
search filter icon
search icon

Document Information

Preface

1.  Covering Multithreading Basics

2.  Basic Threads Programming

3.  Thread Attributes

4.  Programming with Synchronization Objects

5.  Programming With the Oracle Solaris Software

6.  Programming With Oracle Solaris Threads

7.  Safe and Unsafe Interfaces

Thread Safety

MT Interface Safety Levels

Reentrant Functions for Unsafe Interfaces

Async-Signal-Safe Functions in Oracle Solaris Threads

MT Safety Levels for Libraries

Unsafe Libraries

8.  Compiling and Debugging

9.  Programming Guidelines

A.  Extended Example: A Thread Pool Implementation

Index

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 Table 7-1. 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 7-1 Interface Safety Levels

Category
Description
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.


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 Table 7-2_r” routines are supplied in the Oracle Solaris environment.

Table 7-2 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)