What is a reentrant function?
Related Blog Items
- Multithreaded Programming using POSIX pthreads – Part 2
- Bad Standard APIs
- How can I call a C function f(int,char,float) from my C++ code?
- Static volatile const int x=1 valid ?
- Stack
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 - Multithreaded Programming using POSIX pthreads – Part 2
- Bad Standard APIs
- How can I call a C function f(int,char,float) from my C++ code?
- Static volatile const int x=1 valid ?
- Stack
Related Blog Items
- Multithreaded Programming using POSIX pthreads – Part 2
- Bad Standard APIs
- How can I call a C function f(int,char,float) from my C++ code?
- Static volatile const int x=1 valid ?
- Stack
No Comments
No comments yet.