As the name itself suggests, a "reentrant" function (or object or whatever) is a function (or object or whatever) which can be re-entered (entered again) when "there already is something inside" (like the flow). Hence reentrancy is important not only for multithreaded environments, but also for single threaded ones.
Example 1:
void funcA(int x){
static int var = 7;
operateOn(var);
if(conditionMet) funcB(x-1);
operateAgainOn(var);
}
void funcB(int x){
funcA(x);
}
// A call to funcA() yields a call to funcB() which calls funcA()
// again => funcA is RE-ENTERED as the same thread is
// "inside" funcA() two times at once
void funcA(int x){
static int var = 7;
operateOn(var);
if(conditionMet) funcB(x-1);
operateAgainOn(var);
}
void funcB(int x){
funcA(x);
}
// A call to funcA() yields a call to funcB() which calls funcA()
// again => funcA is RE-ENTERED as the same thread is
// "inside" funcA() two times at once
To copy to clipboard, switch view to plain text mode
Example 2: every recursive function.
Bookmarks