in Operating System
293 views
1 vote
1 vote

Which of the following is true? 

  1. A re-entrant procedure can only be called a fixed number of times              
  2. A re-entrant procedure can be called even before the procedure has not returned from it's previous call
  3. Re-entrant procedures can not be called recursively
  4. none of the above
in Operating System
by
293 views

1 comment

I dont understand how option B is false.

Recursive code is an example of reentrant code. Now if I call fibonacci(6), fibonacci(5) would return value before fibonacci(6) and so on. So here fib(5) has returned value before fib(6) as fib(6) is the last function to return value...plz explain @arjun.
0
0

1 Answer

9 votes
9 votes
Best answer

Answer(B)

a procedure is reentrant if it can be interrupted in the middle of its execution, and then be safely called again ("re-entered") before its previous invocations complete execution. The interruption could be caused by an internal action such as a jump or call, or by an external action such as a hardware interrupt or signal. Once the reentered invocation completes, the previous invocations will resume correct execution.

A subroutine that is directly or indirectly recursive should be reentrant. This policy is partially enforced by structured programming languages. However a subroutine can fail to be reentrant if it relies on a global variable to remain unchanged but that variable is modified when the subroutine is recursively invoked.

Source:- https://en.wikipedia.org/wiki/Reentrancy_(computing)

Where we encounter reentrant procedures:-

  • The routine is recursive (or mutually-recursive with some other set of routines).
  • It gets called by another thread.
  • It gets called by an interrupt.

If any of these happen, and the routine is modifying a global (or C static local), then the new execution could potentially wipe out the changes the first execution made. As an example, if that global was used as a loop control variable, it might cause the first execution, when it finally gets to resume, to loop the wrong number of times.

Source:-http://stackoverflow.com/questions/7025857/what-is-a-re-entrant-procedure

selected by
Answer:

Related questions