Path: utzoo!utgpu!attcan!uunet!munnari!vuwcomp!dsiramd!csnz!paul From: paul@csnz.nz (Paul Gillingwater) Newsgroups: comp.unix.wizards Subject: Re: reentrant vs. non-reentrant code Message-ID: <49@csnz.nz> Date: 1 Aug 88 14:44:53 GMT References: <1670001@hpcilzb.HP.COM> Reply-To: paul@csnz.UUCP (Paul Gillingwater) Organization: Computer Sciences of New Zealand, Wellington, NZ Lines: 38 In article <1670001@hpcilzb.HP.COM> tedj@hpcilzb.HP.COM (Ted Johnson) writes: > >Can someone please explain the difference between "reentrant" and >"non-reentrant" code? Thanks! Many of us down-under probably don't bother replying to questions because the delays means that it's already been answered, but what the heck, here goes anyway.... ;-) Back in 1979 when I was writing multi-tasking operating systems for M6800's for process control applications, I found out the hard way the difference. When I wrote modules that might need to be called concurrently to respond to different sources of interrupts, I found that if an interrupt was currently being processed (and it had to be done real fast so no use setting a flag to process later) when another interrupt came in, the code would be executed again (i.e. re-entered) before the first call could finish and clean up after itself. The result of this was that any local variables (read absolute addresses to RAM - this is M6800 assembler, remember!) were overwritten. The solution was simple - just use the X register to maintain a heap - sort of like a stack, only starting at the bottom of RAM. Any local variables then became just offsets from this pointer (which WAS maintained at a fixed place, and had to be accessed under special Test-and-set semaphore control. Of course any decent HLL will look after local variables in a clean manner. So, to summarise, re-entrant code doesn't mind being entered any number of times (subject to stack/heap space), and won't do things that can't be undone. It cleans up after itself (if well written), whilst non-re-entrant code (like the IBM ROM BIOS) doesn't and isn't. MS-DOS - Just say Gnu! -- Paul Gillingwater, Computer Sciences Call this BBS - Magic Tower (24 hours) paul@csnz.nz (vuwcomp!dsiramd!csnz) NZ +64 4 753 561 8N1 TowerNet software P.O.Box 929, Wellington, NEW ZEALAND V21/V23/V22/V22bis/Bell 103/Bell 212A Vox: +64 4 846194, Fax: +64 4 843924 "All things must parse"-ancient proverb