What is the re-engagement procedure?

What is the re-entry procedure and can you give an example usage scenario?

Edit: Also, can multiple processes access the re-entry procedure in parallel ?

Please provide a different way of explanation than Wikipedia, since I do not fully understand their description, so my question is here

+7
source share
3 answers

The idea of ​​re-entry is that a subroutine can be called while it is already in the middle of execution, and it will still work correctly.

This is usually achieved by using only parameters and local variables declared on the stack (in terms of C, no static locals). It would also be important that it does not block any global resources at runtime.

Now you may ask: "How will such a strange thing happen as a routine that is performed several times?" Well, some ways may happen:

  • A subprogram is recursive (or mutually recursive with another set of subprograms).
  • It is called by another thread.
  • It is called by an interrupt.

If any of these events occurs, and the routine modifies the global (or C static local), then the new execution can potentially destroy the changes made first. As an example, if this global was used as a loop control variable, this can lead to the fact that the first execution, when it finally resumes, will loop in the wrong number of times.

+15
source

This is a routine that can be called when it is already active. For example, recursive functions are often repeated. Functions called from signal handlers must also be reentrant. The reentrant function is thread safe, but not all thread safe are reentrant.

+2
source

A repeat procedure is a procedure in which a single copy of a program code can be used by several users for the same period of time. Red has two key aspects: the program code cannot change itself, and local data for each user must be stored separately.

In a common system, re-allocation allows for more efficient use of main memory: one copy of the program code is stored in main memory, but several procedures can invoke a procedure. Thus, the repeated procedure must have a constant part (instructions that make up the procedure) and a temporary part (pointer back to the calling program, as well as memory for local variables used by the program).

Each execution instance, called procedure activation, executes the code in the constant part, but must have its own copy of local variables and parameters. The temporary part associated with a particular activation is called an activation record.

The most convenient way to support reentrant procedures is through the stack. When a repeated procedure is called, the activation record becomes part of the stack frame created when the procedure was called

+1
source

All Articles