Concurrency

Reentrancy

A computer program or subroutine is called reentrant if multiple invocations can safely run concurrently on multiple processors.

I saw this as a Reentrant callback group.

Shaheer was asking me this as a interview question.

Reentrant Procedure

From Appendix P.3. from OS book.

A useful concept, particularly in a system that supports multiple users at the same time, is that of the reentrant procedure. A reentrant procedure is one in which a single copy of the program code can be shared by multiple users during the same period of time.

Reentrancy has two key aspects:

  1. The program code cannot modify itself
  2. the local data for each user must be stored separately.

A reentrant procedure can be interrupted and called by an interrupting program and still execute correctly upon return to the procedure. In a shared system, reentrancy allows more efficient use of main memory: One copy of the program code is kept in main memory, but more than one application can call the procedure.

Thus, a reentrant procedure must have a permanent part (the instructions that make up the procedure) and a temporary part (a pointer back to the calling program as well as memory for local variables used by the program). Each execution instance, called activation, of a procedure will execute the code in the permanent part but must have its own copy of local variables and parameters. The temporary part associated with a particular activation is referred to as an activation record. The most convenient way to support reentrant procedures is by means of a stack. When a reentrant procedure is called, the activation record of the procedure can be stored on the stack. Thus, the activation record becomes part of the stack frame that is created on procedure call.

Concepts