[openbeos] Re: POSIX thread safety, was: Re: Waiting and waiting

> I believe that a "reentrant" function is one which can be safely called
> before a previous call to that same function completes.  This would
> imply lack of self-modifying code, etc., and is more related to
> recursion than thread safety.

No.  Being reentrant has nothing to do with recursion.

Here is a non-reentrant form of a function:

float temp;

float add(a, b)
{
  temp = a;
  temp += b;
  return temp
};

Because thread #1 might start running add, then get interrupted before
adding in "b" to a. Then thread #2 comes along, and runs add, changes the
value for temp.  When thread #1 is resumed, the answer will be wrong.

Isaac


Other related posts: