1. What is reentry?
When the function is being executed, due to external reasons or internal calls, it enters the function execution again.
Second, the reentry scene
- Multiple threads execute the function at the same time
- Function itself calls itself
3. What is reentrant
Under the same input, the function will produce the same result every time it is called.
chestnut:
int add(int a, int b)
{
return a + b;
}
Every time add(1, 2) is called, the result is 3.
Fourth, what characteristics must a reentrant function have?
- Do not use any static or global non-const objects
- Does not return any pointers to static or global non-const objects
- Only rely on the parameters provided by the caller
- Does not rely on any single resource lock
- Do not call any non-reentrant functions