What is Reentrant?

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

  1. Multiple threads execute the function at the same time
  2. 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?

  1. Do not use any static or global non-const objects
  2. Does not return any pointers to static or global non-const objects
  3. Only rely on the parameters provided by the caller
  4. Does not rely on any single resource lock
  5. Do not call any non-reentrant functions

 

Guess you like

Origin blog.csdn.net/xunye_dream/article/details/112444578