This section provides information for writing reentrant and thread-safe programs. It does not cover the topic of writing thread-efficient programs. Thread-efficient programs are efficiently parallelized programs. This can only be done during the design of the program. Reentrance A reentrant function does not hold static data over successive calls, nor does it return a pointer to static data.
All data is provided by the caller of the function.
A reentrant function must not call non-reentrant functions. A non-reentrant function can often, but not always, be identified by its external interface and its usage. For example, the strtok subroutine is not reentrant, because it holds the string to be broken into tokens. Thread-safety concerns only the implementation of a function and does not affect its external interface. In C, local variables are dynamically allocated on the stack.