previous | start | next

Reentrant Functions

A function is reentrant if it can be called "safely" (e.g. by another thread) before execution of the function (e.g. by an initial thread) has finished.

The function foo below is not reentrant since the results of two threads executing foo depend on the timing.

The function bar is also not reentrant because it calls foo.

int x = 1;

int foo()
{
  x = 2 * x;
  return x;
}

int bar()
{
  return foo() + foo();
}


previous | start | next