List of routines safe to use in signals?

Michael Meissner meissner at osf.org
Sat Dec 15 07:37:12 AEST 1990


In article <1960 at necisa.ho.necisa.oz> boyd at necisa.ho.necisa.oz (Boyd
Roberts) writes:

| In article <RANG.90Dec10231747 at nexus.cs.wisc.edu> rang at cs.wisc.edu (Anton Rang) writes:
| >
| >  Anyway, is such a list available on the net somewhere?  Lacking
| >that, is there a reasonable heuristic to guess what's safe?
| >

	...

| Set a flag in the signal handler and check for it elsewhere in
| the code.  Keep it simple and you won't get burned.

Note that unless you are careful, even setting a flag may not be safe,
if it takes more than one instruction to store the value.  Off the top
of my head, this can happen because of:

   1)	Using an int flag on an 8-bit micro, which requires 2 or more
	instructions to store the various pieces.

   2)	Using a char flag on a RISC machine which has no byte
	addressing modes, and does store bytes by loading the word,
	and/or-ing the value into place, and storing the word.

   3)	Using an int flag on a CISC machine which doesn't align
	things, the flag may span page boundaries, and you catch
	things in the middle of a page fault.

ANSI specifies that the vendor must provide 'sig_atomic_t' in which it
is guaranteed to be safe to store static/global flags from signal
handlers.  Using 'char' will proably work on most of the machines (but
of course not all).
--
Michael Meissner	email: meissner at osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Considering the flames and intolerance, shouldn't USENET be spelled ABUSENET?



More information about the Comp.unix.programmer mailing list