Reentrant POSIX thread functions (_POSIX_THREAD_SAVE_FUNCTIONS group)
Functions with the "_r" suffix in the name are functions that are the reentrant version of the corresponding function without the "_r" suffix. Since these functions are also useful when working with threads, they are also supplied in the unthreaded version of CRTE
($.SYSLNK.CRTE).
“asctime_r - convert date and time to string (thread-safe)”
“ctime_r - thread-safe conversion of date and time to string”
“getgrgid_r - get group file entry for group ID (thread-safe)”
“getgrnam_r - get group file entry for group name (thread-safe)”
“getlogin_r - get login name (thread-safe)”
“getpwnam_r - get user name (thread-safe)”
“gmtime_r - convert date and time to UTC (thread-safe)”
“localtime_r - convert date and time to string (thread-safe)”
“rand_r - pseudo-random number generator (int, thread-safe)”
“readdir_r - read directory (thread-safe)”
“strtok_r - split string into tokens (thread-safe)”
“ttyname - find pathname of terminal”
These functions are to be used when working with threads instead of using the corresponding function that does not have the suffix "_r". However, it is also advantageous to use the functions listed in a unthreaded environment.
POSIX THREAD functions for locking and unlocking objects of type (FILE*)
“flockfile, ftrylockfile, funlockfile - functions for locking standard input/output”
POSIX thread functions for explicitly locking clients
The following functions are identical to the corresponding functions without "_unlocked" in the name:
In this case the user must guarantee thread safety himself by locking the object of type (FILE*) used by calling the flockfile or ftrylockfile function and by calling the funlockfile function to unlock it.
POSIX thread functions that affect a process or thread
There are two kinds of POSIX thread functions
- Functions that affect the process (just like before) and therefore affect all threads belonging to the process and
- Functions that only affect a special thread
You must also check when using signals if the signal is sent to the (entire) process or to a certain thread.
The following functions are available in this context:
“alarm - schedule alarm signal”
“atexit - register function to run at process termination”
“exit, _exit - terminate process”
“getcontext, setcontext - display or modify user context”
"getrlimit - get limit value for a resource" in chapter "getrlimit, setrlimit - get or set limit for resource"
"getpriority - call process priority" in chapter "getpriority, setpriority - get or set process priority"
“kill - send signal to process or process group”
“msgrcv - receive message from queue”
“msgsnd - send message to queue”
“nice - change priority of process”
“pause - suspend process until signal is received”
“raise - send signal to calling process”
“semop - semaphore operations”
“setcontext - modify user context”
“setlocale - set or query locale”
“sigaction - examine and change signal handling”
“sigpause - remove signal from signal mask and deactivate process”
“sigpending - examine pending signals”
“sigsetjmp - set label for non-local jump using signal”
“sigsuspend - wait for signal”
“sleep - suspend process for fixed interval of time”
“usleep - suspend process for defined interval”
“wait, waitpid - wait for child process to stop or terminate”
“wait3 - wait for status change of child processes”
“waitid - wait for status change of child processes”
For the following functions the SIGPIPE
signal is not sent to the process but is sent to the calling thread instead when an EPIPE
error occurs:
“fputwc - put wide-character code on stream”
“fseek - reposition file position indicator in stream”
Functions that are not safe for threads
All functions that are defined in the C runtime library are safe for threads as delivered. The following functions are the only exceptions to this rule:
“asctime - convert date and time to string" 1)
“basename - return last element of pathname”
“brk, sbrk - modify size of data segment”
“chroot - change root directory”
“ctime, ctime64 - convert date and time to string" 1)
"dbmclearerr - function for administering dbm databases" on "dbm_clearerr, dbm_close, dbm_delete, dbm_error, dbm_fetch, dbm_firstkey, dbm_nextkey, dbm_open, dbm_store - functions for managing dbm databases"
“ecvt, fcvt, gcvt - convert floating-point number to string”
“endgrent, getgrent, setgrent - group management”
“endpwent, getpwent, setpwent - manage user catalog”
“endutxent, getutxent, getutxid, getutxline, pututxline, setutxent - manage utmpx entries”
“fcvt - convert floating-point number to string”
“gamma - compute logarithm of gamma function”
“gcvt - convert floating-point number to string”
“getdtablesize - get size of descriptor table”
“getenv - get value of environment variable”
“getgrent - get group file entry”
“getpwent - read user data from user catalog”
“getutxent, getutxid, getutxline - get utmpx entry”
“getgrgid - get group file entry for group ID” 1)
“getgrnam - get group file entry for group name” 1)
“getlogin - get login name” 1)
“getpagesize - get current page size”
“getpass - read string of characters without echo”
“getw - read word from stream”
"initstate - generate pseudo-random number" on "initstate, random, setstate, srandom - generate pseudo-random numbers" 2)
“localtime, localtime64 - convert date and time to local time” 1)
“longjmp - execute non-local jump” 3)
“ptsname - name of pseudoterminal”
“putenv - change or add environment variables”
“pututxline - write utmpx entry”
“rand - pseudo-random number generator (int)” 2)
"random - create pseudo-random numbers" 2)
“sbrk - modify size of data segment”
“setgrent - reset file position indicator to beginning of group file”
“setpwent - delete pointer to search user catalog”
“setutxent - reset pointer to utmpx file”
“siglongjmp - execute non-local jump using signal” 3)
“signgam - variable for sign of lgamma”
“sigprocmask - examine or change blocked signals” 4)
“sigset - modify signal handling”
“strtok - split string into tokens” 1)
“ttyname - find pathname of terminal” 1)
“ttyslot - find entry of current user in utmp file”
“wait3 - wait for status change of child processes”
Note | If you use one of the |
1) | use reentrant function ("_r" extension) |
2) | use |
3) | The result of calling this function is undefined when the |
4) | use |