In C I know about the recursive function but I heard about the re-entrant function.
What is that? And whats the difference between them?
Reentrant functions can be called recursively and can be called simultaneously by two or more processes. Reentrant functions are often required in real-time applications or in situations where interrupt code and non-interrupt code must share a function.
Reentrant and Recursive procedures. • Reentrant procedures: The procedure which can be interrupted, used and “reentered” without losing or writing over anything. • Recursive procedure: It is the procedure which call itself.
A reentrant function does not hold static data over successive calls, nor does it return a pointer to static data. All data is provided by the caller of the function. A reentrant function must not call non-reentrant functions.
A re-entrant function is one that can be interrupted (typically during thread context-switching), and re-entered by another thread without any ill-effect. Functions that rely on a local variable are considered re-entrant due to the fact that their variables are safely encapsulated between threads.
It's easier to remember when you understand what the term means.
The term "re-entrant" means that it is safe to "re-enter" the function while it is already executed, typically in a concurrent environment.
In other words, when two tasks can execute the function at the same time without interfering with each other, then the function is re-entrant. A function is not re-entrant when the execution by one task has an impact on the influence of another task. This typically is the case when a global state or data is used. A function that uses only local variables and arguments is typically re-entrant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With