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 |
|
|
_fdopen_r _mkstemp_r _remove_r
|
72 |
|
|
_fopen_r _mktemp_r _rename_r
|
73 |
|
|
_getchar_r _perror_r _tempnam_r
|
74 |
|
|
_gets_r _putchar_r _tmpnam_r
|
75 |
|
|
_iprintf_r _puts_r _tmpfile_r
|
76 |
|
|
|
77 |
|
|
@exdent @emph{Signal functions:}
|
78 |
|
|
_raise_r _signal_r
|
79 |
|
|
|
80 |
|
|
@exdent @emph{Stdlib functions:}
|
81 |
|
|
@c FIXME! dtoa undoc; should _dtoa_r be mentioned?
|
82 |
|
|
_dtoa_r _realloc_r _strtoul_r
|
83 |
|
|
_free_r _srand_r _system_r
|
84 |
|
|
_malloc_r _strtod_r
|
85 |
|
|
_rand_r _strtol_r
|
86 |
|
|
|
87 |
|
|
@exdent @emph{String functions:}
|
88 |
|
|
_strtok_r
|
89 |
|
|
|
90 |
|
|
@exdent @emph{System functions:}
|
91 |
|
|
_close_r _lseek_r _stat_r
|
92 |
|
|
_fork_r _open_r _unlink_r
|
93 |
|
|
_fstat_r _read_r _wait_r
|
94 |
|
|
_link_r _sbrk_r _write_r
|
95 |
|
|
|
96 |
|
|
@exdent @emph{Time function:}
|
97 |
|
|
_asctime_r
|
98 |
|
|
@end example
|