Reentrancy (computing) - Rules For Reentrancy

Rules For Reentrancy

Reentrant code may not hold any static (or global) non-constant data.
Reentrant functions can work with global data. For example, a reentrant interrupt service routine could grab a piece of hardware status to work with (e.g. serial port read buffer) which is not only global, but volatile. Still, typical use of static variables and global data is not advised, in the sense that only atomic read-modify-write instructions should be used in these variables (it should not be possible for an interrupt or signal to come during the execution of such an instruction).
Reentrant code may not modify its own code.
The operating system might allow a process to modify its code. There are various reasons for this (e.g., blitting graphics quickly) but this would cause a problem with reentrancy, since the code might not be the same next time.
It may, however, modify itself if it resides in its own unique memory. That is, if each new invocation uses a different physical machine code location where a copy of the original code is made, it will not affect other invocations even if it modifies itself during execution of that particular invocation (thread).
Reentrant code may not call non-reentrant computer programs or routines.
Multiple levels of 'user/object/process priority' and/or multiprocessing usually complicate the control of reentrant code. It is important to keep track of any access and or side effects that are done inside a routine designed to be reentrant.

Read more about this topic:  Reentrancy (computing)

Famous quotes containing the word rules:

    The average educated man in America has about as much knowledge of what a political idea is as he has of the principles of counterpoint. Each is a thing used in politics or music which those fellows who practise politics or music manipulate somehow. Show him one and he will deny that it is politics at all. It must be corrupt or he will not recognize it. He has only seen dried figs. He has only thought dried thoughts. A live thought or a real idea is against the rules of his mind.
    John Jay Chapman (1862–1933)