what is a re-entrant code? again what is re-entrant kernel?
thank you ece tech
what is a re-entrant code?
Code (for example a function) that can be called safely while the same function is already being run by another task/program/function.
Reentrancy is needed, for example, for recursive function calls, or for functions that are called from multiple tasks without any kind of mutex mechanism.
Now here is another question: how do you test for reentrancy of such code?
You don't test for reentrancy. You specifically develop with that in mind. Reentrancy is a factor of what resources the function makes use of, and how it uses them.
An example is that if a function needs to change two global variables (and these variables must always be in sync, then the change must be atomic. An example is allocating/releasing memory.
Another example is that a function that reads a global resource may have to protect the read access, to make sure that two instances of the same function reads the same value and then does an updated based on the same value. For example a function that reads a counter, performs some work based on the counter and then increment the counter. If two instances of the same function checks that there are data available in a read queue, they may both process the same character and insert two results based on the same input.
Note that a reentrant function may only call other reentrant functions.
Another example is that a function that reads a global resource may have to protect ........
Pers post abbreviated: stay away from reentrancy.
Erik
stay away from reentrancy.
To be more precise - on a '51, stay away from situations where you may need reentrant functions (e.g. recursive functions, multithreading, calling the same function in ISRs and the regular program, etc)
View all questions in Keil forum