Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between re-entrant function and recursive function in C?

Tags:

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?

like image 975
Manoj Doubts Avatar asked Nov 04 '08 09:11

Manoj Doubts


People also ask

Is reentrant recursive?

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.

What is reentrant and recursive procedure?

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.

What is the difference between reentrant and non-reentrant functions?

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.

What are re-entrant 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.


1 Answers

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.

like image 163
user34005 Avatar answered Dec 25 '22 11:12

user34005