Reentrant |
A computer program or routine is described as reentrant if it is designed in such a way that a single copy of the program s instructions in memory can be shared by multiple users or separate computer process. The key to designing a reentrant program is to ensure that no portion of the program code is modified by the different users/processes, and that process-unique information (such as local variables) is kept in a separate area of memory that is distinct for each user or process.
Reentrant programming is key to many systems of computer multitasking.
The kernel code or the code implementing synchronization like Semaphore_(programming) is generally not reentrant because it handles the shared memory.
= Examples =
In the following piece of code, both functions f and g are not reentrant.
int g_var = 1; int f () { g_var = g_var + 2; return g_var; } int g () { return f () + 2; }
In the above, f depends on a global variable g_var ; thus, if two processes execute it and access to g_var concurrently, then the result varies depending on the timing of the execution. Hence, f is not reentrant. Neither is g; it calls f, which is not reentrant.
= See also =
= External links =
|
|