Path: utzoo!attcan!uunet!tektronix!tekig5!larryha From: larryha@tekig5.PEN.TEK.COM (Larry Hattery) Newsgroups: comp.sys.mac.programmer Subject: Re: what the heck is "reentrant"? Message-ID: <3111@tekig5.PEN.TEK.COM> Date: 5 Aug 88 20:25:08 GMT References: <730049@hpcilzb.HP.COM> <104700046@p.cs.uiuc.edu> Reply-To: larryha@tekig5.PEN.TEK.COM (Larry Hattery) Organization: Tektronix, Inc., Beaverton, OR. Lines: 25 Reentrant routines only become an issue in a multitasking OS where a routine may get suspended before it is finished and the same routine gets called again by another task. The same is true for routines called by interrupt handlers. Any time a routine can be called from more than one place, conceptually, at the same time, it should be reentrant. This means that it must provide mutual exclusion around any global resources it is using to insure that subsequent calls to the same routine will not screw things up for the call that hasn't yet completed. Here, global also means static variables in the routine itself since these refer to the same location from call to call. Of course, any stack based variables are private to a particular instance of the call and do not need protection. Mutual exculsion is generally handled with semaphores, or more radically by disabling interrupts, while in critical sections of a routine which would fail if the routine were reentered at that point. I'm excluding rescursive routines because they are by definition, and presumably be design, reentrant. -- Larry E. Hattery Tektronix Inc. larryha@penguin.PEN.TEK.COM M/S 47-704 Portable Instruments Division PO Box 500 (503)627-1225 days Beaverton, OR 97077