540 views
1 votes
1 votes

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

1 Answer

Best answer
9 votes
9 votes

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

2 votes
2 votes
1 answer
1
Bikram asked Sep 3, 2016
293 views
Match these OS abstractions with Hardware components:A. Thread1. interruptB. Virtual address space2. memoryC. File system3. CPUD. Signal4. DiskA-2 B-4 C-3 D-1A-1 B-2 C-3 ...
3 votes
3 votes
1 answer
2
Bikram asked Sep 3, 2016
355 views
Semaphores are used to solve the problem ofresource allocationprocess synchronizationdeadlockprocess communication
3 votes
3 votes
1 answer
3
2 votes
2 votes
2 answers
4