[Expat-discuss] Definition Of Re-entrant

Joe Wiemann JWieman@daktronics.com
Mon, 13 Aug 2001 15:04:51 -0500


Reentrancy - 

One of the real beauties of multi threading is that the same C function can be called from multiple threads.... This provides great power and reduces code space... however, it does require that C functions called from multiple threads are reentrant.

What does reentrant mean? Basically a reentrant function stores the caller's return address on the stack and does not rely on global or static C variables that it previously set up.  Most compilers place the return address on the stack. hence application developers must only worry about the use of globals and statics.

An example of a non-reentrant function is strtok found in the standard C library.  This function remembers the previous string pointer on subsequent calls. it does this with a static string pointer.  if this function is called from multiple threads, it would most likely return an invalid pointer.

 - Taken from threadx user manual.


>>> "Fred L. Drake, Jr." <fdrake@acm.org> 08/13/01 10:25AM >>>

Rich Salz writes:
 > Informally, re-entrant means that it is safe to call the function while
 > an existing call is pending:  can I *re-enter* the function?  An

  This is certainly what I'm more familiar with...


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation


_______________________________________________
Expat-discuss mailing list
Expat-discuss@lists.sourceforge.net 
http://lists.sourceforge.net/lists/listinfo/expat-discuss