📄 reent.tex
字号:
@node Reentrancy@chapter Reentrancy@cindex reentrancyReentrancy is a characteristic of library functions which allows multipleprocesses to use the same address space with assurance that the values storedin those spaces will remain constant between calls. The Red Hatnewlib implementation of the library functions ensures that whenever possible, these library functions are reentrant. However,there are some functions that can not be trivially made reentrant.Hooks have been provided to allow you to use these functions in a fullyreentrant fashion.@findex _reent@findex reent.h@cindex reentrancy structureThese hooks use the structure @code{_reent} defined in @file{reent.h}.A variable defined as @samp{struct _reent} is called a @dfn{reentrancystructure}. All functions which must manipulate global information areavailable in two versions. The first version has the usual name, anduses a single global instance of the reentrancy structure. The secondhas a different name, normally formed by prepending @samp{_} andappending @samp{_r}, and takes a pointer to the particular reentrancystructure to use.For example, the function @code{fopen} takes two arguments, @var{file}and @var{mode}, and uses the global reentrancy structure. The function@code{_fopen_r} takes the arguments, @var{struct_reent}, which is apointer to an instance of the reentrancy structure, @var{file}and @var{mode}. There are two versions of @samp{struct _reent}, a normal one and onefor small memory systems, controlled by the @code{_REENT_SMALL}definition from the (automatically included) @file{<sys/config.h>}.@cindex global reentrancy structure@findex _impure_ptrEach function which uses the global reentrancy structure uses the globalvariable @code{_impure_ptr}, which points to a reentrancy structure.This means that you have two ways to achieve reentrancy. Both requirethat each thread of execution control initialize a unique globalvariable of type @samp{struct _reent}:@enumerate@item@cindex extra argument, reentrant fnsUse the reentrant versions of the library functions, after initializinga global reentrancy structure for each process. Use the pointer to thisstructure as the extra argument for all library functions.@itemEnsure that each thread of execution control has a pointer to its ownunique reentrancy structure in the global variable @code{_impure_ptr},and call the standard library subroutines.@end enumerate@cindex list of reentrant functions@cindex reentrant function listThe following functions are provided in both reentrantand non-reentrant versions.@example@exdent @emph{Equivalent for errno variable:}_errno_r@exdent @emph{Locale functions:}_localeconv_r _setlocale_r@exdent @emph{Equivalents for stdio variables:}_stdin_r _stdout_r _stderr_r@page @exdent @emph{Stdio functions:}_fdopen_r _perror_r _tempnam_r_fopen_r _putchar_r _tmpnam_r_getchar_r _puts_r _tmpfile_r_gets_r _remove_r _vfprintf_r_iprintf_r _rename_r _vsnprintf_r_mkstemp_r _snprintf_r _vsprintf_r_mktemp_t _sprintf_r@exdent @emph{Signal functions:}_init_signal_r _signal_r_kill_r __sigtramp_r_raise_r@exdent @emph{Stdlib functions:}_calloc_r _mblen_r _setenv_r_dtoa_r _mbstowcs_r _srand_r_free_r _mbtowc_r _strtod_r_getenv_r _memalign_r _strtol_r_mallinfo_r _mstats_r _strtoul_r_malloc_r _putenv_r _system_r_malloc_r _rand_r _wcstombs_r_malloc_stats_r _realloc_r _wctomb_r@exdent @emph{String functions:}_strdup_r _strtok_r@exdent @emph{System functions:}_close_r _link_r _unlink_r_execve_r _lseek_r _wait_r_fcntl_r _open_r _write_r _fork_r _read_r_fstat_r _sbrk_r_gettimeofday_r _stat_r_getpid_r _times_r@ifset STDIO64@exdent @emph{Additional 64-bit I/O System functions:}_fstat64_r _lseek64_r _open64_r@end ifset@exdent @emph{Time function:}_asctime_r@end example
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -