Xref: utzoo comp.unix.wizards:20199 comp.windows.x:17115 comp.sys.hp:4011 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!apple!bionet!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.wizards,comp.windows.x,comp.sys.hp Subject: Re: Interrupted library calls Keywords: Xlib, library, signals, longjmp Message-ID: <11970@smoke.BRL.MIL> Date: 17 Jan 90 14:57:14 GMT References: <373@node17.mecazh.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn) Followup-To: comp.unix.wizards Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 32 In article <373@node17.mecazh.UUCP> paul@mecazh.UUCP (Paul Breslaw) writes: >This is especially so if the signal is allowed to interrupt any old bit of >code that might be updating some data structure that is subsequently needed. >And this, of course, is what happened when certain Xlib routines were >interrupted. >That leaves 3 - but whose responsibility is it to defend the data in the >library - the implementor or the user? >Clearly this is a general problem, but I do not recall seeing anything >about it on the net. The relevant properties are reentrancy and noninterruptibility. These issues were recognized by the various standardization groups. For example, ANSI C requires that signal() be invokable within any signal handler, and that a signal handler function terminate only via return, abort(), exit(), or longjmp(). IEEE 1003.1 adds a large number of ("system call") functions that are required to be invokable reentrantly or else block signals during their operation (so that reentrance is not possible). The X/Open Portability Guide adds chroot() to this list and imposes these constraints on abort(), exit(), and longjmp() (which are therefore hard to implement!). Note that stdio functions and other similar library functions were NOT so constrained, in order to avoid paying a run-time penalty on each use of these heavily-used functions. However, some vendors of multiprocessor implementations of UNIX have decided to go ahead and use semaphores to protect critical regions within such library functions, in order to prevent the kind of problem you encountered. Unless the specification of a library function states that it is safe to abort or reenter it, you the application programmer should take steps to avoid doing so.