Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

22
May

What is a reentrant function?

Related Blog Items

A reentrant function is one that can be used by more than one task concurrently without fear of data corruption.Whereas, a non-reentrant function is one that cannot be shared by more than one task unless mutual exclusion to the function is ensured either by using a semaphore or by disabling interrupts during critical sections of code.A reentrant function can be interrupted at any time and resumed at a later time without loss of data. Reentrant functions either use local variables or protect their data when global variables are used.

In the early days of programming, non-reentrancy was not a threat to programmers; functions did not have concurrent access and there were no interrupts. In many older implementations of the C language, functions were expected to work in an environment of single-threaded processes.However, now concurrent programming is common practice and one should be aware of the pitfalls.It will be very difficult to figure out the bug caused when a signal handling functions triggers a non-reentrant function.

Typically a reentrant function does not hold static data over successive calls, does not return a pointer to static data,should not call any non-reentrant functions, uses local data or protection of global data by taking a local copy of the variable.

Typically a non-reentrant function calls a malloc or free, uses the static data structures, will be a part of input-output operations.

Popularity: 13%

You need to log on to convert this article into PDF


Related Blog Items

No Comments

No comments yet.

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image