|
For other uses of the term, see Reentrant (disambiguation).
A computer program or routine is described as reentrant if it can be safely executed concurrently; that is, the routine can be re-entered while it is already running. To be reentrant, a function must:
Multiple levels of 'user/object/process priority' and/or multiprocessing usually complicate the control of reentrant code. Also, IO code is usually not reentrant because it relies on shared, singleton resources such as disks. Reentrancy is a key feature of functional programming.
ExamplesIn the following piece of C code, neither functions
int g_var = 1;
int f()
{
g_var = g_var + 2;
return g_var;
}
int g()
{
return f() + 2;
}
In the above, These slightly-altered versions are reentrant:
int f(int i)
{
return i + 2;
}
int g(int i)
{
return f(i) + 2;
}
Relation to thread-safetyBoth concepts of reentrancy and thread-safety relate to the way functions handle resources. However, they are not the same. While the concept of reentrancy can affect the external interface of a function, thread-safety only concerns the implementation of the function and not its external interface.
Therefore, reentrancy is a more fundamental property than thread-safety and by definition, leads to thread-safety: Every reentrant function is thread-safe, however, not every thread-safe function is reentrant. See alsoExternal links
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.
Mercedes Car
This site monitored by SitePinger.net