Thursday, September 01, 2005

critical sections - thread-safety and re-entrancy

Re-entrant function definitions:
  1. Code which can have multiple simultaneous, interleaved, or nested invocations which will not interfere with each other.
  2. A function is reentrant if, while it is being executed, it can be re-invoked by itself (recursion), or by any other routine, by interrupting the present execution for a while.
Thread-safe function definitions:
  1. A description of code which is either re-entrant or protected from multiple simultaneous execution by some form of mutual exclusion.
  2. A function which can be called simultaneously by multiple threads when each invocation references shared data.
Comparisons:
  1. Re-entrancy is stronger condition of the two (Thread-safety and Reentrancy).
  2. Thread-safety guarantees mutual exclusion or serialized access of shared resources that may be modified. Re-entrancy guarantees no shared resources or just read-only access to shared resources and maintenance of local state for every re-entry.
  3. Every re-entrant function is necessarily thread-safe, but vice-versa is false.

0 Comments:

Post a Comment

<< Home