what the heck is "reentrant"?

Orr Michael orr at taux02.UUCP
Wed Aug 10 06:43:10 AEST 1988


   A simple way to understand this, (though not really a full definition) is
Like this:
   A piece of code is "Re-entrant" if two (or more) processes can execute
   its' code at the same time. "at the same time" means that each process
   can have its' program counter pointing into the same code area, so that
   when either process is made (by the OS) to run, an instruction of the same
   code will be executed next. This makes it necessary for Re-entrant code
   to be "pure", i.e. instructions only, no data, because each process excuting
   that code expects its' own data, though they are all running the same code.
   Example :
   say you have a sort program. if it is written so that 
   1. the data to be sorted is accessed only through pointers
   2. these pointers are initialized as part of the code

[Nit-pickers : I know both of the above are NOT essential, and not the only
 way to do this. this is just an example, hopefully clarifying my meaning]

   then 1 process may start using the program, get to the point where the
   data pointers are initialized and start sorting, and then, if another
   process starts running, and it wants to sort too, it can simply execute
   the same instructions the 1st process did. since the pointers will be
   initialized again, this time pointing to different data, all will be well,
   and both processes can co-exist.
   This is most usefull for programs in common use by many users at once,
   e.g. editors, shells, etc.
-- 
orr%@nsc.NSC.COM		  	      IBM's motto: Machines should work,
{amdhal,decwrl,hplabs,pyramid,sun}!nsc!orr             People should think.
                                 	      Orr's remark: Neither do.
Disclaimer: Opinions, come home. All is forgiven. Papa.



More information about the Comp.lang.c mailing list