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 words rules for and/or rules:
“Logic teaches rules for presentation, not thinking.”
—Mason Cooley (b. 1927)
“There is all the difference in the world between departure from recognised rules by one who has learned to obey them, and neglect of them through want of training or want of skill or want of understanding. Before you can be eccentric you must know where the circle is.”
—Ellen Terry (18471928)