1 |
39 |
lampret |
@node Reentrancy
|
2 |
|
|
@chapter Reentrancy
|
3 |
|
|
|
4 |
|
|
@cindex reentrancy
|
5 |
|
|
Reentrancy is a characteristic of library functions which allows multiple
|
6 |
|
|
processes to use the same address space with assurance that the values stored
|
7 |
|
|
in those spaces will remain constant between calls. Cygnus's implementation
|
8 |
|
|
of the library functions ensures that
|
9 |
|
|
whenever possible, these library functions are reentrant. However,
|
10 |
|
|
there are some functions that can not be trivially made reentrant.
|
11 |
|
|
Hooks have been provided to allow you to use these functions in a fully
|
12 |
|
|
reentrant fashion.
|
13 |
|
|
|
14 |
|
|
@findex _reent
|
15 |
|
|
@findex reent.h
|
16 |
|
|
@cindex reentrancy structure
|
17 |
|
|
These hooks use the structure @code{_reent} defined in @file{reent.h}.
|
18 |
|
|
A variable defined as @samp{struct _reent} is called a @dfn{reentrancy
|
19 |
|
|
structure}. All functions which must manipulate global information are
|
20 |
|
|
available in two versions. The first version has the usual name, and
|
21 |
|
|
uses a single global instance of the reentrancy structure. The second
|
22 |
|
|
has a different name, normally formed by prepending @samp{_} and
|
23 |
|
|
appending @samp{_r}, and takes a pointer to the particular reentrancy
|
24 |
|
|
structure to use.
|
25 |
|
|
|
26 |
|
|
For example, the function @code{fopen} takes two arguments, @var{file}
|
27 |
|
|
and @var{mode}, and uses the global reentrancy structure. The function
|
28 |
|
|
@code{_fopen_r} takes the arguments, @var{struct_reent}, which is a
|
29 |
|
|
pointer to an instance of the reentrancy structure, @var{file}
|
30 |
|
|
and @var{mode}.
|
31 |
|
|
|
32 |
|
|
@cindex global reentrancy structure
|
33 |
|
|
@findex _impure_ptr
|
34 |
|
|
Each function which uses the global reentrancy structure uses the global
|
35 |
|
|
variable @code{_impure_ptr}, which points to a reentrancy structure.
|
36 |
|
|
|
37 |
|
|
This means that you have two ways to achieve reentrancy. Both require
|
38 |
|
|
that each thread of execution control initialize a unique global
|
39 |
|
|
variable of type @samp{struct _reent}:
|
40 |
|
|
|
41 |
|
|
@enumerate
|
42 |
|
|
@item
|
43 |
|
|
@cindex extra argument, reentrant fns
|
44 |
|
|
Use the reentrant versions of the library functions, after initializing
|
45 |
|
|
a global reentrancy structure for each process. Use the pointer to this
|
46 |
|
|
structure as the extra argument for all library functions.
|
47 |
|
|
|
48 |
|
|
@item
|
49 |
|
|
Ensure that each thread of execution control has a pointer to its own
|
50 |
|
|
unique reentrancy structure in the global variable @code{_impure_ptr},
|
51 |
|
|
and call the standard library subroutines.
|
52 |
|
|
@end enumerate
|
53 |
|
|
|
54 |
|
|
@cindex list of reentrant functions
|
55 |
|
|
@cindex reentrant function list
|
56 |
|
|
The following functions are provided in both reentrant
|
57 |
|
|
and non-reentrant versions.
|
58 |
|
|
|
59 |
|
|
@example
|
60 |
|
|
@exdent @emph{Equivalent for errno variable:}
|
61 |
|
|
_errno_r
|
62 |
|
|
|
63 |
|
|
@exdent @emph{Locale functions:}
|
64 |
|
|
_localeconv_r _setlocale_r
|
65 |
|
|
|
66 |
|
|
@exdent @emph{Equivalents for stdio variables:}
|
67 |
|
|
_stdin_r _stdout_r _stderr_r
|
68 |
|
|
|
69 |
|
|
@page
|
70 |
|
|
@exdent @emph{Stdio functions:}
|
71 |
56 |
joel |
_fdopen_r _perror_r _tempnam_r
|
72 |
|
|
_fopen_r _putchar_r _tmpnam_r
|
73 |
|
|
_getchar_r _puts_r _tmpfile_r
|
74 |
|
|
_gets_r _remove_r _vfprintf_r
|
75 |
|
|
_iprintf_r _rename_r _vsnprintf_r
|
76 |
|
|
_mkstemp_r _snprintf_r _vsprintf_r
|
77 |
|
|
_mktemp_t _sprintf_r
|
78 |
39 |
lampret |
|
79 |
|
|
@exdent @emph{Signal functions:}
|
80 |
56 |
joel |
_init_signal_r _signal_r
|
81 |
|
|
_kill_r __sigtramp_r
|
82 |
|
|
_raise_r
|
83 |
39 |
lampret |
|
84 |
|
|
@exdent @emph{Stdlib functions:}
|
85 |
|
|
@c FIXME! dtoa undoc; should _dtoa_r be mentioned?
|
86 |
56 |
joel |
_calloc_r _mblen_r _srand_r
|
87 |
|
|
_dtoa_r _mbstowcs_r _strtod_r
|
88 |
|
|
_free_r _mbtowc_r _strtol_r
|
89 |
|
|
_getenv_r _memalign_r _strtoul_r
|
90 |
|
|
_mallinfo_r _mstats_r _system_r
|
91 |
|
|
_malloc_r _rand_r _wcstombs_r
|
92 |
|
|
_malloc_r _realloc_r _wctomb_r
|
93 |
|
|
_malloc_stats_r _setenv_r
|
94 |
39 |
lampret |
|
95 |
|
|
@exdent @emph{String functions:}
|
96 |
|
|
_strtok_r
|
97 |
|
|
|
98 |
|
|
@exdent @emph{System functions:}
|
99 |
56 |
joel |
_close_r _link_r _unlink_r
|
100 |
|
|
_execve_r _lseek_r _wait_r
|
101 |
|
|
_fcntl_r _open_r _write_r
|
102 |
|
|
_fork_r _read_r
|
103 |
|
|
_fstat_r _sbrk_r
|
104 |
|
|
_gettimeofday_r _stat_r
|
105 |
|
|
_getpid_r _times_r
|
106 |
39 |
lampret |
|
107 |
|
|
@exdent @emph{Time function:}
|
108 |
|
|
_asctime_r
|
109 |
|
|
@end example
|